Author Topic: C++ bit field question  (Read 4274 times)

0 Members and 1 Guest are viewing this topic.

Offline z80man

  • Casio Traitor
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 977
  • Rating: +85/-3
    • View Profile
C++ bit field question
« 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.

« Last Edit: March 06, 2011, 02:57:51 am by z80man »

List of stuff I need to do before September:
1. Finish the Emulator of the Casio Prizm (in active development)
2. Finish the the SH3 asm IDE/assembler/linker program (in active development)
3. Create a partial Java virtual machine  for the Prizm (not started)
4. Create Axe for the Prizm with an Axe legacy mode (in planning phase)
5. Develop a large set of C and asm libraries for the Prizm (some progress)
6. Create an emulator of the 83+ for the Prizm (not started)
7. Create a well polished game that showcases the ability of the Casio Prizm (not started)

Offline compu

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 275
  • Rating: +63/-3
    • View Profile
Re: C++ bit field question
« Reply #1 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(;
???

Offline z80man

  • Casio Traitor
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 977
  • Rating: +85/-3
    • View Profile
Re: C++ bit field question
« Reply #2 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

List of stuff I need to do before September:
1. Finish the Emulator of the Casio Prizm (in active development)
2. Finish the the SH3 asm IDE/assembler/linker program (in active development)
3. Create a partial Java virtual machine  for the Prizm (not started)
4. Create Axe for the Prizm with an Axe legacy mode (in planning phase)
5. Develop a large set of C and asm libraries for the Prizm (some progress)
6. Create an emulator of the 83+ for the Prizm (not started)
7. Create a well polished game that showcases the ability of the Casio Prizm (not started)

Offline Binder News

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 785
  • Rating: +46/-3
  • Zombie of Tomorrow
    • View Profile
Re: C++ bit field question
« Reply #3 on: March 06, 2011, 08:44:08 am »
I would say change the #defines to typedefs
Spoiler For userbars:







Hacker-in-training!   Z80 Assembly Programmer     Axe Programmer
C++ H4X0R             Java Coder                           I <3 Python!

Perdidisti ludum     Cerebrum non habes

"We are humans first, no matter what."
"Fame is a vapor, popularity an accident, and riches take wings. Only one thing endures, and that is character."
Spoiler For Test Results: