473,385 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

size of enum in vc6

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

Jul 22 '05 #1
6 5784
HEnk wrote:
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
Jul 22 '05 #2
HEnk wrote:
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.
Jul 22 '05 #3

"HEnk" <no****@nospam.com> wrote in message
news:c4**********@reader11.wxs.nl...
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.
Jul 22 '05 #4

"HEnk" <no****@nospam.com> wrote in message
news:c4**********@reader11.wxs.nl...
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.
Jul 22 '05 #5
HEnk wrote:
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.

--
Regards,
Buster.
Jul 22 '05 #6
HEnk wrote:
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.

--
Regards,
Buster.
Jul 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: HEnk | last post by:
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...
6
by: Cheng Mo | last post by:
I tried in g++ sizeof(int*) siezof(long*) sizeof(Foo*)//Foo is a self-defined class They all has same size. Do all pointers have same size in a given platform with given compiler? Thanks &...
7
by: Aryeh M. Friedman | last post by:
If have something like the following declartion: enum foo {One,Two,....,Ten}; How do I determine how many elements (enumerations)... in this case it is obviously 10 but I don't want to hard...
3
by: Andy Venikov | last post by:
Sometimes you want to use a bitfield to hold an enum value. In such cases you would only use as many bits as are needed to encode the full set of enum values. And it is a pain to recompute and...
2
by: Stephan Schulz | last post by:
Hi, in my standard scanner/parser package I am using a typedef enum to enumerate possible tokens, with each token type corresponding to a power of two, somewhat like the following: typedef...
3
by: Jonathan Avraham | last post by:
Hi, If you don't want to read the whole story: I'm asking - Can I force gcc to treat all enums as 2-byte integers? If you need more details - read on: I'm trying to write an embedded program...
4
by: Bilgehan.Balban | last post by:
Hi, The following code: #include <stdio.h> // const int const_asize = 10; #define define_asize = 10; int array = {1,2,3,4,5,6,7,8,9,0};
5
by: Francois Grieu | last post by:
Can an enum be used as an array size? In other word, is this legal? enum {n=1}; int a; int main(void){return a;} TIA
8
by: ypjofficial | last post by:
Hi all, In what way does the enumerated data type contibute to the size of a class if its part of that class? eg. #include <iostream.h> class one { public:
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.