warning variable 'will be initialized later'

P

pritisrathi

Hi All,
I have a union which is a public data member of a class. This union has
one anonymous structure. The structure is like :
union abc
{
unsigned char byte;
struct
{
unsigned char rec_ : 5;
unsigned char type_ : 2;
unsigned char dir_ : 1;
};
};

I am getting compiler warning 'will be initialized later' for struct
member that is for rec_, type_ and dir_. I am using gcc3.3 for
compilation.
How to remove this warning?
TIA,
Priti
 
M

mlimber

Hi All,
I have a union which is a public data member of a class. This union has
one anonymous structure. The structure is like :
union abc
{
unsigned char byte;
struct
{
unsigned char rec_ : 5;
unsigned char type_ : 2;
unsigned char dir_ : 1;
};
};

I am getting compiler warning 'will be initialized later' for struct
member that is for rec_, type_ and dir_. I am using gcc3.3 for
compilation.
How to remove this warning?
TIA,
Priti

It's probably because your structure member has no name, which is
non-standard. Try changing it to something like:

union abc
{
unsigned char byte;
struct
{
unsigned char rec_ : 5;
unsigned char type_ : 2;
unsigned char dir_ : 1;
} s;
};


Cheers! --M
 
P

Pete Becker

mlimber said:
It's probably because your structure member has no name, which is
non-standard.

Bit-fields are not required to have names. If you don't name it you
can't do anything with it, so it only provides padding.
 
M

mlimber

Pete said:
Bit-fields are not required to have names. If you don't name it you
can't do anything with it, so it only provides padding.

I'm not sure if you're disagreeing with me or not, but in any case,
Comeau online and EDG (via Dinkumware) both reject the OP's union as
non-standard.

Cheers! --M
 
P

Pete Becker

mlimber said:
I'm not sure if you're disagreeing with me or not, but in any case,
Comeau online and EDG (via Dinkumware) both reject the OP's union as
non-standard.

I see: "structure member" is ambiguous. I took it to mean "the member of
the struct", which is what he's trying to access. You meant "the struct
that's a member of the union," which is, indeed, invalid.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top