By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,819 Members | 1,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,819 IT Pros & Developers. It's quick & easy.

bit array in C++

P: n/a
The following piece of code compiles under C (gcc 3.4.2)

typedef struct {
unsigned int padding[16]:1;
unsigned int holes[16]:1;
} triangle_bitmap_t;

However I get the error "invalid member function declaration" when I
try to compile it with C++ compiler (g++ 3.4.2). Any idea what might I
be doing wrong.

Dec 9 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
hondya wrote:
The following piece of code compiles under C (gcc 3.4.2)

typedef struct {
unsigned int padding[16]:1;
unsigned int holes[16]:1;
} triangle_bitmap_t;

However I get the error "invalid member function declaration" when I
try to compile it with C++ compiler (g++ 3.4.2). Any idea what might I
be doing wrong.

The error is a bit obtuse, but there is no such thing as a bit array.
A bitfield identifier must either be applied directly to the identifier
name or be an unnamed one. You can't apply it to an array .
Dec 9 '05 #2

P: n/a
Is it a C++ limitation/bug? Because the same thing works in C.

Dec 9 '05 #3

P: n/a

hondya wrote:
Is it a C++ limitation/bug?

No, its a syntax error. Bitfields cannot be applied for arrays.

the same thing works in C.


C is not C++ and C++ is not C.

Dec 9 '05 #4

P: n/a
hondya wrote:
Is it a C++ limitation/bug? Because the same thing works in C.


It's illegal in C as well. If your C compiler allowed, then it is some
sort of extension.

Brian

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
Dec 9 '05 #5

P: n/a
hondya wrote:
The following piece of code compiles under C (gcc 3.4.2)


gcc 3.4.5 reject this code with error: bit-field `...' has invalid type.

Dec 10 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.