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 6 5785
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
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.
"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.
"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.
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.
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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 &...
|
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...
|
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...
|
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...
|
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...
|
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};
|
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
|
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:
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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
|
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...
|
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: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |