• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 918
  • Last Modified:

UCHAR vardata[0] gives warning

Hi everybody,
I am using VC++ ver 5.0, and when I compile my colleague's
code containing the below in the header file :---

#pragma pack(1)
typedef struct {
    /* Header */
    WORD    Total_length;
    ...
    UCHAR   vardata[0];
}
MY_HEADER;
#pragma pack()

a warning is given out as :---
abc.h(55) : warning C4200: nonstandard extension used :
                                       zero-sized array in struct/union

So how can I fix the code to avoid this warning???

Thanks for your help.
Regards,
Eric
0
e1
Asked:
e1
  • 3
  • 3
  • 2
1 Solution
 
V_BapatCommented:
You can disable the warning using #pragma directive.

#pragma warning(disable : 4200)
0
 
V_BapatCommented:
#pragma warning(disable : 4200)
typedef struct {
    /* Header */
    WORD    Total_length;
    ...
    UCHAR   vardata[0];
}
MY_HEADER;
#pragma warning(default : 4200)

For more details look for #pragma in MSDN help.

Vicky
0
 
V_BapatCommented:
Initially I thought you wanted to hide this warning.
After reading the question again, I think you want to remove the warning. If this is the case please reject the answer and treat it as comment.

Vicky
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
naveenkohliCommented:
HEre is your problem .... Why did ya assign the size of array to be zero? Atleast provide space for one elemnt in UCHAR array....

********UCHAR   vardata[0]; *********
Can't be ZERO ...
0
 
naveenkohliCommented:
change your code to this
#pragma pack(1)
typedef struct {
    /* Header */
    WORD    Total_length;
    UCHAR   vardata;
}
MY_HEADER;
#pragma pack()

or you can specify the number of chars you want in vardata ... line vardata[n] {n > 0)
0
 
e1Author Commented:
Thanks V_Bapar and naveenkohli.
The code was written by a former colleague and I guess I just have to change my code to
    UCHAR vardata;

hi naveenkohli, could you submit an answer so I can give you the mark.

Thanks again.
0
 
naveenkohliCommented:
HEre is the blank answer :-)

Cheers!
0
 
e1Author Commented:
Thanks again !!!
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now