typedef stuct problem in C

后端 未结 2 1402
陌清茗
陌清茗 2021-01-29 11:16

I am facing a weird problem I have defined I a structure in a C header file:

typedef struct iRecActive{

    char iRecSID[32];
    unsigned char RecStatus;
             


        
相关标签:
2条回答
  • 2021-01-29 11:28

    I tried to find solution for similar problem but I didn't find it on stack. I leave here answer for other people, to save their time:

    Because it is C, you cannot create your variables where you want. They must be created at the beginning of statement. So this is correct:

    if(true) {
       iRecActive_t myRecActive;
       //calculations
       Mutex_Lock(somemutext);
       variable = 14;
    

    And this is incorrect:

    if(true) {
       //calculations
       Mutex_Lock(somemutext);
       variable = 14;
       iRecActive_t myRecActive;
    

    In last example you get error message: illegal use of this type as expression or some other similar, very useful errors.

    Proper question is here, but it was marked as duplication (it is not!): typedef stuct problem in C (illegal use of this type as an expression)

    Regards, Ikeban

    0 讨论(0)
  • 2021-01-29 11:55

    change iRecAcitve_t to iRecActive_t.

    0 讨论(0)
提交回复
热议问题