struct has an illegal zero-sized array
struct has an illegal zero-sized array
when i was trying to compile ntfs-3g, i find the error message.
it seems that zero size array is not allowed in some structs in msvc 8.
or may be i m wrong.
i googled the problem.
but never find any solution.
can anybody help me getting around this.
it seems that zero size array is not allowed in some structs in msvc 8.
or may be i m wrong.
i googled the problem.
but never find any solution.
can anybody help me getting around this.
Re: struct has an illegal zero-sized array
Zero-sized arrays are usually variable-sized arrays used for serialization to and from disk, with their length specified in a preceding field.
Because of their variable-sized-ness, they usually appear at the end of a struct. It is therefore usually safe to replace them with an array size of 1, instead of 0. This is unless the sizeof(struct) is taken, in which case there is no safe replacement and the MSVC warning must be disabled.
Because of their variable-sized-ness, they usually appear at the end of a struct. It is therefore usually safe to replace them with an array size of 1, instead of 0. This is unless the sizeof(struct) is taken, in which case there is no safe replacement and the MSVC warning must be disabled.
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Re: struct has an illegal zero-sized array
Hmm, why are you compiling ntfs-3g with MSVC? Doesn't Windows already have an NTFS driver (considering it's been around since at least 2003, and is used by XP, Vista and 7)?
Re: struct has an illegal zero-sized array
i was stripping the nessesary file so that i can add it to my os project
Re: struct has an illegal zero-sized array
djgpp support zerro sized array in structure.
is there any way to force msvc to support zerro sized array.
well,
msvc works fine on the following:
struct abcd
{
int a;
int b;
int c;
char d[0];
}
but when i do the following it show the error
struct abcd
{
int a;
char b[0];
int c;
char d[0];
}
is there any way to force msvc to support zerro sized array.
well,
msvc works fine on the following:
struct abcd
{
int a;
int b;
int c;
char d[0];
}
but when i do the following it show the error
struct abcd
{
int a;
char b[0];
int c;
char d[0];
}
- NickJohnson
- Member
- Posts: 1249
- Joined: Tue Mar 24, 2009 8:11 pm
- Location: Sunnyvale, California
Re: struct has an illegal zero-sized array
IIRC, the C99 standard only allows zero-sized arrays at the end of structures, because they're supposed to be used to add a variable length array to the end of a structure. It's reasonable that MSVC would reject the second example, not to mention that abcd.b == &(abcd.c), so having b is redundant and useless (unless you're trying to make a union of b and c or something).
- Owen
- Member
- Posts: 1700
- Joined: Fri Jun 13, 2008 3:21 pm
- Location: Cambridge, United Kingdom
- Contact:
Re: struct has an illegal zero-sized array
C99 variable length arrays should be declared "Type name[]" anyway. [0] is a deprecated GCC extension.
Not that this helps you. You're trying to compile C99 code on MSVC, which doesn't support it.
Not that this helps you. You're trying to compile C99 code on MSVC, which doesn't support it.
Re: struct has an illegal zero-sized array
i found a new way.
the following works fine.
typedef struct
{
int a;
union
{
char b[1];
unsigned int c;
};
char d[0];
} abcd;
thanks to everybody for replying
the following works fine.
typedef struct
{
int a;
union
{
char b[1];
unsigned int c;
};
char d[0];
} abcd;
thanks to everybody for replying
Re: struct has an illegal zero-sized array
Are anonymous unions standard C? I can't find it in the standard and I am finding different answers on the web.
EDIT: To answer my own question, according to GCC they aren't. I tried to compile the following code:With the following results:
EDIT: To answer my own question, according to GCC they aren't. I tried to compile the following code:
Code: Select all
struct foo
{
union
{
long l;
float f;
};
};
struct foo bar;
long test1(void)
{
return bar.l;
}
float test2(void)
{
return bar.f;
}
Code: Select all
gcc -c -std=gnu99 -pedantic test.c
test.c:8: warning: ISO C doesn't support unnamed structs/unions
test.c:9: warning: struct has no named members
Code: Select all
gcc -c -std=c99 -pedantic test.c
test.c:8: warning: ISO C doesn't support unnamed structs/unions
test.c:8: warning: declaration does not declare anything
test.c:9: warning: struct has no members
test.c: In function `test1':
test.c:15: error: structure has no member named `l'
test.c: In function `test2':
test.c:20: error: structure has no member named `f'