#Does it matter where I declare a static const in my file?

20 messages · Page 1 of 1 (latest)

sick prawn
#

Do I need to write all my static const declarations at the start of my single file project or is it fine to put them closer to where they are used for readability?

stable ravineBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

chrome bolt
sick prawn
#

It's allocated before the program starts either way?

chrome bolt
#

yeah, all static initialization runs before main()

#

(not counting static init inside of functions)

sick prawn
#

Is there a way and / or is it desirable to tag the types of those variables when you first use them?

chrome bolt
ionic star
#

and what would be the purpose of that?

chrome bolt
#

identifying whether var was initialized or not

#

this only makes sense for static objects in functions though

ionic star
#

I find it somewhat dubious

chrome bolt
#

well, it doesn't make sense if they're in the same scope

#
void awoo() {
    static bool var_used = false;
    if (something) {
        static T var = (var_used = true, T(...));
        ...
    }
    ...
}
#

but yeah, it's pretty dubious

sick prawn
#

I dunno, just seemed convenient to make it clear what type a variable is, if it was initialized a lot earlier in the file?

chrome bolt
#

syntax highlighters usually give different colors to local variables, function parameters, and globals

stable ravineBOT
#

This question is being automatically marked as stale.
If your question has been answered, run !solved.
If your question is not answered feel free to bump the post or re-ask.
Take a look at !howto ask for tips on improving your question.

chrome bolt
#

!solved