size of enum in vc6

H

HEnk

Hi,

I have a Borland BCB3 program that has structs with enums.
The default behaviour of BCB3 is that the sizeof an enum will be 1 byte if
the maximum value fits in 8 bits. I am now porting this code to vc6. In vc6,
enums seem to be always 4 bytes.
Because the structs are stored in files (in BCB3 format = 1 byte per enum),
I need to get the VC6 compiler to use also a size of 1 byte for those enums.
I cannot find an appropiate cl switch.
My question is, is there a way to do this?
Thanks, Henk
 
P

Pete

HEnk said:
Hi,

I have a Borland BCB3 program that has structs with enums.
The default behaviour of BCB3 is that the sizeof an enum will be 1
byte if the maximum value fits in 8 bits. I am now porting this code
to vc6. In vc6, enums seem to be always 4 bytes.
Because the structs are stored in files (in BCB3 format = 1 byte per
enum), I need to get the VC6 compiler to use also a size of 1 byte
for those enums. I cannot find an appropiate cl switch.
My question is, is there a way to do this?
Thanks, Henk

I don't believe there is, but you might try asking in
microsoft.public.vc.lanugauge to be sure.
Though I would suggest changing the enum to several const unsigned chars,
and using an unsigned char in the struct.

- Pete
 
B

Bill Seurer

HEnk said:
My question is, is there a way to do this?

Check the documentation for the compiler again. Almost all of them have
ways of changing the enum size by a pragma or compilation option.
 
N

Nick Hounsome

HEnk said:
Hi,

I have a Borland BCB3 program that has structs with enums.
The default behaviour of BCB3 is that the sizeof an enum will be 1 byte if
the maximum value fits in 8 bits. I am now porting this code to vc6. In vc6,
enums seem to be always 4 bytes.
Because the structs are stored in files (in BCB3 format = 1 byte per enum),
I need to get the VC6 compiler to use also a size of 1 byte for those enums.
I cannot find an appropiate cl switch.
My question is, is there a way to do this?
Thanks, Henk

As you have found out binary files are not usually portable.

A bitfield can have enumeration type so that might solve your problem.
 
B

Buster

HEnk said:
I have a Borland BCB3 program that has structs with enums.
The default behaviour of BCB3 is that the sizeof an enum will be 1 byte if
the maximum value fits in 8 bits. I am now porting this code to vc6. In vc6,
enums seem to be always 4 bytes.
Because the structs are stored in files (in BCB3 format = 1 byte per enum),
I need to get the VC6 compiler to use also a size of 1 byte for those enums.
I cannot find an appropiate cl switch.
My question is, is there a way to do this?

My suggestion is that you write a function,

std::istream & read_thing (std::istream & stream, thing & x)
{
typedef boost::uint8_t enum_on_disk_t;
// Use whatever type is binary-compatible with BCB3 enum, if any.

// ...
{
enum_on_disk_t x;
stream.read (reinterpret_cast <char *> (& x), sizeof x);
thing.enumeration_field_1 =
reinterpret_cast <enumeration_type_1> (x);
// TODO: separate this into its own function?
}
// ...
}

Then call this function instead of doing a raw memory read.
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top