Search code examples
cstructstorage-class-specifier

How to specify storage class specifier for an object of struct without a name?


I am using a struct like:

struct{
    int a;
    char b[100];
}name;

I want to use static storage class specifier on name. How can I do that?


Solution

  • use the word static in front of it:

    static struct{
        int a;
        char b[100];
    } name;
    

    This will declare a variable named name with the type struct { ... } and the storage class specifier static.

    To initialize the member of the struct, you can use

    static struct{
        int a;
        char b[100];
    } name = {5};