Would like to know why cannot I declare a Static variable in for loop initialization as shown below,
for(static int i = 0;;)
Compiling the above loop statement code with my C99 standard compiler I see the below error,
error: declaration of static variable ‘i’ in ‘for’ loop initial declaration
C does not allow it
C11dr 6.8.5 Iteration statements 3
"The declaration part of a for statement shall only declare identifiers for objects having storage class auto or register".
(not static)
Typically code would not benefit form being able to have an iterator that is static.
storage-class-specifier:
typedef
extern
static
_Thread_local
auto
register
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With