Omnimaga

General Discussion => Technology and Development => Computer Programming => Topic started by: z80man on March 06, 2011, 12:52:34 am

Title: C++ bit field question
Post by: z80man on March 06, 2011, 12:52:34 am
Alright I was compiling my Prizm emulator when I came upon an error. As a global variable I had defined a bit field of 1 byte that is split into two 4 bit variables. I then used a #define to rewrite the bit field so that I would not have to label the the struct name. Here is an eample of  the error I got.
unsigned int n = half_byteone;
spectrum.cpp(291: Error: '(' expected following simple type name
Code: (error areas) [Select]
struct middle_byte                       //creates a bit feld for reading the middle byte of an instruction
{
unsigned char half_byteone:4;
unsigned char half_bytetwo:4;
};
unsigned char low_byte;   //creates low byte of instruction

 #define half_byteone middle_byte.half_byteone
 #define half_bytetwo middle_byte.half_bytetwo
blah...
void ADD() //ADD Rm,Rn
{
unsigned int n = half_byteone;   //291
unsigned int m = half_bytetwo;
R[n] += R[m];
PC += 2;
return;
}
blah...
half_byteone = (instruction & 0x0F00) / 0x100;     // inside the function that calls ADD()
half_bytetwo = (instruction & 0x00F0) / 0x10;
This error appears every time I reference the bit field not just this one example. When I googled this error I found that fixing it involved some sort of weird work with templates (which I have never used before :P) Some help on getting this to work would be greatly appreciated.

Title: Re: C++ bit field question
Post by: compu on March 06, 2011, 02:50:44 am
Could you mark line 291 please?

Or is it just this typo?
Quote
unsigned int n = half_byteone(;
???
Title: Re: C++ bit field question
Post by: z80man on March 06, 2011, 02:58:53 am
Could you mark line 291 please?

Or is it just this typo?
Quote
unsigned int n = half_byteone(;
???
Yeah that was just a typo. It is not actually in the code. And I marked 291 as a comment
Title: Re: C++ bit field question
Post by: Binder News on March 06, 2011, 08:44:08 am
I would say change the #defines to typedefs