Automatic Variable

Would an variable defined thusly:

const uint8_t dog;

inside of a function still be considered an automatic variable and regenerated on the stack every time the function is called even though the 'const' directive is included? My guess is yes, it needs to be 'static' to avoid regeneration. But, others may know better.

Thanks.

First: No, it will never be put on the stack, because it is a constant. It will be optmized away by the compiler, and replaced by its value wherever it is used.

Second: You can’t declare a constant, and NOT initialize its value. What would be the point of a constant with no valule?

Regards,
Ray L.

OK, my bad. I over simplified it. Suppose the variable is a big honking array. It will be an array of constants with an initializer. Given that, what will be the difference between defining it in a function (say loop) verses making it a global? Assuming it's only used in that function.

gfvalvo: Suppose the variable is a big honking array. It will be an array of constants with an initializer.

I would place such a beast into PROGMEM. If you want to keep its scope local it probably should be static.

Alright, for the sake of argument, here's the choices:

const uint8_t bigArray[] = {1,2, 3, 4, 5, 6, 7, 8, 9, 10};
void loop() {

}
void loop() {
const uint8_t bigArray[] = {1,2, 3, 4, 5, 6, 7, 8, 9, 10};

}
void loop() {
static const uint8_t bigArray[] = {1,2, 3, 4, 5, 6, 7, 8, 9, 10};

}

Given those (and only those) choices, what will be the difference in how the array will be assigned to memory and will the second one be regenerated every time loop() is entered?

There is no PROGMEM choice, why?

const uint8_t bigArray[] PROGMEM = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
void loop() {
}

Whandall: There is no PROGMEM choice, why?

Because I already know what PROGMEM will do. I'm looking for an understanding, not a solution.

http://stackoverflow.com/questions/13415321/difference-between-static-auto-global-and-local-variable-in-the-context-of-c-a

OK, thanks. That didn't cover my Choice #2 explicitly. But since that case doesn't contain the 'static' directive, I read that the array must be an Automatic Variable with a lifetime that ends when loop() exits. Therefore, all the 'const' directive does is tell the compiler not to let me modify its values during runtime.

Sorry I wasn't clearer in my first post. Would have saved some replies.