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
e1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
e1Author Commented:
Thanks again !!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.