nim - Difference between a const inside a proc vs outside -
this dumb question, other visibility there real difference between const
inside proc
vs outside?
const foo = "foo" proc test() = const bar = "bar" echo foo & bar test()
like when inside, stack grow , shrink const
every time proc
invoked, or because it's const
held in static memory location duration of application?
i'm asking nim reflections on differences/similarities in other languages welcome too.
if @ generated c code, see line:
string_literal(tmp139, "foobar", 6);
what tells foo & bar
evaluated @ compile time.
nimbase.h
has this:
#define string_literal(name, str, length) \ static const struct { \ tgenericseq sup; \ nim_char data[(length) + 1]; \ } name = {{length, length}, str}
const
in nim more static memory location. seem in case string "foobar"
in static memory location. however, if replace these strings numbers, example, 1
, 3
, generated code has 4
literal without storage.
now, actual question. difference here scope in constants seen.
if wasn't simplified in such way (e.g. if wrote echo foo\\echo bar
), can consult generated code again , see 2 identical (except content) string_literal
declarations.
Comments
Post a Comment