Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Typedef structure's member being static or not in c

I think this none sense doesnt that? because after creating instance from that variable. It will initialize that variable whole, will not behave differently to members an will initialize all of them, doesn’t that? As I know static variables are global variable but their usage are restricted to specified function or source file.

typedef struct
{
    const uint32_t mainpointer;
    static uint32_t currentpointer;    
    uint16_t num_el;    
    uint8_t num_byte;    
}arrayPushCirc_doublebuffer_instance;

void main(void)
{
arrayPushCirc_doublebuffer_instance struction;
function1(struction);
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

In C data members of a structure may not have storage class specifiers.

So this declaration of a data member

static uint32_t currentpointer;

is invalid in C.

According to the C Grammar data member declarations may have only the following specifiers

specifier-qualifier-list:
    type-specifier specifier-qualifier-listopt
    type-qualifier specifier-qualifier-listopt

On the other hand, you may use the storage class specifier static for declarations of objects in teh file scope.

For example

#include <stdint.h>

typedef struct
{
    const uint32_t mainpointer;
    uint32_t currentpointer;    
    uint16_t num_el;    
    uint8_t num_byte;    
}arrayPushCirc_doublebuffer_instance;

static arrayPushCirc_doublebuffer_instance struction; 

int main( void )
{
    //...
}

Pay attention to that according to the C Standard the function main without parameters shall be declared like

int main( void )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading