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 > dmaCopy problem

#93753 - spencer723 - Fri Jul 21, 2006 12:31 am

For some reason when I try this:
Code:
dmaCopy(myBG_bin, BG_TILE_RAM_SUB(0), myBG_bin_size);


I get the error:
Code:
error: invalid conversion from 'int' to 'void*'
error: initializing argument 2 of 'void dmaCopy(const void*, void*, uint32)'


Anyone have any idea what's going on? It's worked before but now it won't compile

#93755 - tepples - Fri Jul 21, 2006 12:49 am

How is BG_TILE_RAM_SUB() defined? And did it "work[] before" in C when you are now using C++?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#93756 - spencer723 - Fri Jul 21, 2006 1:05 am

I'm afraid I'm not following you tepples :S

#93757 - tepples - Fri Jul 21, 2006 1:08 am

  1. The expression BG_TILE_RAM_SUB(0) looks like the evaluation of a preprocessor macro. In which header file is this macro defined?
  2. Are you using the C language, or are you using the C++ language?
  3. Was the program where the code "worked before" written in the C language, or was it written in the C++ language?
  4. Exactly what do you not understand about these questions?

_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#93767 - spencer723 - Fri Jul 21, 2006 4:11 am

1. It is defined in <nds/arm9/video.h>
2. C++
3. Same program, different Makefile
4. Just the wording of your question caught me

#93771 - tepples - Fri Jul 21, 2006 4:47 am

spencer723 wrote:
1. It is defined in <nds/arm9/video.h>

Then the answer to "How is it defined?" is
Code:
#define BG_TILE_RAM_SUB(base) (((base)*0x4000) + 0x06200000)

Notice the lack of a cast to any pointer type here.

Quote:
2. C++

ISO C++ is much stricter about pointer casting than C ever was:
Code:
// In your code, you'll need to replace this expression
BG_TILE_RAM_SUB(base)

// with this expression
reinterpret_cast<void *>(BG_TILE_RAM_SUB(base))

_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#93797 - parrot_ - Fri Jul 21, 2006 9:18 am

I'm sure just adding (void*) works too.
_________________
Squak! etc.
My Blog

#93820 - spencer723 - Fri Jul 21, 2006 1:52 pm

Ahh, I knew I forgot something, thanks!

#93878 - tepples - Fri Jul 21, 2006 7:51 pm

parrot_ wrote:
I'm sure just adding (void*) works too.

Right, but C style casting will likely be dropped in future versions of C++.

Synonyms:
Code:
reinterpret_cast<type>(expr) // C++ way
(type) expr // C way

// The portable way
#ifdef __cplusplus
  #define CAST(type, expr) (reinterpret_cast<type>(expr))
#else
  #define CAST(type, expr) ((type)(expr))
#endif

_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#93882 - Sausage Boy - Fri Jul 21, 2006 8:07 pm

I don't think C style casting will be dropped, as it will brake almost every larger program in existance. That's just stupid.
_________________
"no offense, but this is the gayest game ever"

#93905 - PeterM - Fri Jul 21, 2006 10:22 pm

The reason C++ has extra casts is to make the purpose of the code clear to the reader.

static_cast is for conversions which are somewhat sane (base* -> subclass*, float -> int etc)
reinterpret_cast is the dangerous one (int <-> ptr etc)
dynamic_cast does runtime error checking for silly casts (cat* -> sheep* etc)
const_cast is for casting away consts (indicative of lazy programming somewhere)

What I do is just use static_cast, and the compiler will tell me if that's not good enough.

Whereas C just has a plain old cast, and you've go to figure out WTF the coder was thinking yourself.
_________________
http://aaiiee.wordpress.com/

#93919 - HyperHacker - Sat Jul 22, 2006 12:06 am

...Which is where comments come in.

Isn't C++ supposed to be backward compatible anyway?
_________________
I'm a PSP hacker now, but I still <3 DS.

#93956 - tepples - Sat Jul 22, 2006 2:29 am

The C++ language is not a strict superset of the C language. It's a superset of a fairly comprehensive subset of the C language. If you have a C program with variables called 'throw', 'xor', 'template', or 'new', it is not a valid C++ program.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.