`static` has two meanings in C: for variables declared within a function, static qualification means they will retain their value between invocations of the function. For global variables, static qualification means those variables will not be accessible from outside the file they're declared in.
In C qualifying a member of a struct as static doesn't make any sense. Static qualification of a struct will have different effects based on where the struct is declared, as above.
`const` can be applied at either the struct level, and will apply to the entire struct, or at the member level, and apply to only that member. One thing to particularly watch out for is with pointers, where the application of const can be a bit surprising if you're not used to the way that C declarations work (which is admittedly kind of obtuse). If you have:
struct foo {
const int * ptr;
}
The value of the integer pointed to by the pointer will be const, whereas with:
const struct bar {
int * ptr;
}
the value of the pointer, that is, the memory location it targets, is const, because the struct that contains that pointer is const.
To answer your question if you want the entire struct to be static const, then make the struct static const rather than every member. If you're typedefing the struct then you can leave the static/const qualification out of the typedef and then you can apply those qualifications to each instance as needed:
typedef struct my_struct_t {
char[10] string;
int a;
} my_struct_t;
my_struct_t foo;
const my_struct_t bar = {
.string = "hello",
.a = 42,
}
As far as getting variables to be stored in flash, this is dependent on the target and the compiler. const doesn't necessarily mean that a qualified variable will end up in flash, although this may be the default behavior in many compilers, including arm-gcc. There are also specific extensions you can use to explicitly place objects in particular parts of memory depending on the compiler--in GCC this would be a section attribute, which can also be used to place variables or other objects in specific areas of ram, for example in 'tightly coupled' memory regions that may offer improved performance. Other platforms, particularly architectures that don't have a contiguous memory layout between flash and ram, require additional steps to place data in flash and may require extra steps to read those values from flash. For example in AVR, you would need to use the PROGMEM and pgm_read_ family of macros for this.