Being global variables, their lifetime should be infinite, so I believe the
must always be gcsafe. Is that the compiler that does not understand that
global variables cannot be garbage collected?
Another option, if this is a microservice where changes in configuration can
come with a recompilation:
const
SERVER_HOST* {.strdefine.} = "localhost"
SERVER_PORT* {.intdefine.} = 5000
proc test {.gcsafe.} =
echo (SERVER_HOST, SERVER_PORT)
when isM
let is immutable, as the address of the variable can be taken. Once an address
is received, it can outlive its lifetime
So after going through the nim manual i found out that you can overide the
compilers gc safe analysis to assign non gc safe variables to local proc
variables like so
{.cast(gcsafe).}:
let
SERVER_HOST = SERVER_HOST
SERVER_PORT = SERVER_PORT
I have these let variables
from os import getEnv
from strutils import parseInt, isEmptyOrWhitespace
let
SERVER_HOST* : string = block :
var host : string = "localhost" ## default host localhost
let env_host = getEnv("H