gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Promblem With c++

#150283 - dexter0 - Fri Feb 01, 2008 3:06 pm

Perhaps it is my strong Java background but I just can't see how you would write a game (easily) without object oriented programming that C lacks. So, I'm trying to use C++.

Anyway, I am trying to compile a main.cpp file for the ARM7 however I receive the following error. The error only is thrown when the file is a cpp file. If it is C (main.c), it works fine.

error: invalid conversion from 'int' to 'IRQ_MASK'
error: initializing argument 1 of 'void irqEnable(IRQ_MASK)'


Code:
irqEnable(IRQ_VBLANK | IRQ_VCOUNT);

_________________
"It is better to keep your mouth shut and appear stupid than to open it and remove all doubt." ~ Mark Twain

#150287 - myersn024 - Fri Feb 01, 2008 3:50 pm

What version of devkitARM are you using? I write all my stuff in C++ and haven't had any problems like what you're having with my DS development. I did have some similar problems when I started converting all my PSP programs to C++, though. Try wrapping any header files that you know for sure aren't native C++ with the extern "C" wrapper.

Code:
extern "C" {
  #include <your header file #1>
  #include <your header file #2>
}

#150289 - PypeBros - Fri Feb 01, 2008 3:54 pm

C++ is more rigid at enums and typically considers that ENUM_MEMBER|ENUM_MEMBER is a regular int, rather than another member of the enum.

Indeed, declaring the enum in an extern "C" block should do the trick, though it's usually the job of the library editor, not of the library user ...
_________________
SEDS: Sprite Edition on DS :: modplayer

#150315 - yellowstar - Fri Feb 01, 2008 8:58 pm

dexter0 wrote:

error: invalid conversion from 'int' to 'IRQ_MASK'
error: initializing argument 1 of 'void irqEnable(IRQ_MASK)'


Code:
irqEnable(IRQ_VBLANK | IRQ_VCOUNT);


I get around that with this:
Code:

irqEnable((IRQ_MASK)(IRQ_VBLANK | IRQ_VCOUNT);

#150318 - myersn024 - Fri Feb 01, 2008 10:23 pm

I always forget about type casting.

#150323 - dexter0 - Sat Feb 02, 2008 12:51 am

The type casting worked great. That was the first thing I tried but I did it wrong looking back at it.

Thanks
_________________
"It is better to keep your mouth shut and appear stupid than to open it and remove all doubt." ~ Mark Twain