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.

Beginners > Hello World

#8196 - David Zuchora - Fri Jul 04, 2003 6:15 am

Hello World
Hello all!
I'm a newbie and I was wondering if it would be better to learn C or C++ for developing GBA games. Thank You

#8199 - sgeos - Fri Jul 04, 2003 8:56 am

David Zuchora wrote:
Hello World
Hello all!
I'm a newbie and I was wondering if it would be better to learn C or C++ for developing GBA games. Thank You


I do not think it really matters. In my opinion, and it's only my opinion, go with C. I can't back that with anything other than 'I use C and it works for me.'

-Brendan

#8201 - antysix - Fri Jul 04, 2003 11:56 am

I'd also say got for C, because it easier to learn than C++ and C also works better for me (but maybe that's because I don't know C++ very well).
_________________
Currently playing: NGC: Metroid Prime
GBA: Golden Sun: The Lost Age

Currently developping: Project ~ [ Phail ]

#8203 - jcpredator - Fri Jul 04, 2003 12:24 pm

I would suggest you start with C. C++ can be useful in many situations but unless your very experienced with the language I wouldn't suggest using it. C++ will run slower than C without the proper optimizations, but C will run just fine even with spagetti code (sloppy code). In the end though its all your decision...
_________________
There is no spoon...

#8218 - David Zuchora - Fri Jul 04, 2003 6:15 pm

Thanks! I think I'll go with C
_________________
...End Transmission

#8258 - Ninja - Sat Jul 05, 2003 10:20 pm

Use whichever you are best with. Personally I use C++ as I can't program very well in C at all. It works just fine for me, but if you are better with C, power to you.

#8310 - yaustar - Tue Jul 08, 2003 1:02 am

just a curious question, is there a lot of difference in the syntax of C and C++?

Or is it a completely different language?
_________________
[Blog] [Portfolio]

#8313 - niltsair - Tue Jul 08, 2003 2:41 am

The syntax is pretty much the same.

C++ has some differents libraries. The major changes between the two is that c++ introduced Object orited programming and function overloading (having X functions with the same name, but differrents parameters).

Someone with more knowledge on the matter would have to fillup the blanks I left out.

#8355 - yaustar - Tue Jul 08, 2003 11:40 pm

So to get c++ to run at it's best speed, would it be best not to use anything C++ specfic?
_________________
[Blog] [Portfolio]

#8358 - niltsair - Wed Jul 09, 2003 2:09 am

No you can use C++ specific things. What i've read so far(and not really tested) is tha the only major slow down are the use of virtual fucntions, and of templates, beside that, feel free to use C++ specific syntax (namely class).

Another thing to avoid (unrelated to C++ specific) is the use of float variables, unless it's for limited testing purpose. It'll bring your GBA to a crawl because the CPU doesn't support floating math arithmetic.

#8359 - yaustar - Wed Jul 09, 2003 2:14 am

thanks for that.

Do you know if there is a more specfic do's and don'ts guide out there somewhere?
_________________
[Blog] [Portfolio]

#8381 - Sweex - Wed Jul 09, 2003 1:45 pm

niltsair wrote:
No you can use C++ specific things. What i've read so far(and not really tested) is tha the only major slow down are the use of virtual fucntions, and of templates, beside that, feel free to use C++ specific syntax (namely class).


Virtual functions, allright. I can imagine that accessing the vtable takes some time (I doubt whether it's a big impact, but I can't confirm or deny it as I never ran tests on this)

Templates slow? Not possible! Simply because templates only exist in compile-time. When compiling, it will build all the necessary functions for the different used types. It will slow down compiletime and make a bigger ELF, but at runtime it is already known what function to run. So there is no reason why templates should slow down at all.

#8385 - niltsair - Wed Jul 09, 2003 2:41 pm

This is from Tepple's Faq :
Quote:
Q: Should I use C or C++?
To achieve good performance in C++: don't overuse virtual methods or exceptions, turn off support for RTTI (run-time type identification; if you think you need it, your polymorphism may be poorly designed), and use template types only sparingly. This will make C++ almost as fast as C.
I don't why this is, but it's what i've read. Tepple or Jason would be better suited to anwser this one.

As for other optimisation, avoid multiplication or worst, division when you can. They are slow operation. Instead you might use bitshift which are really fast. So instead of doing :
x * 256 --> x<<8
x * 24 --> x<<4 + x<<3 explanation 24 = 2^4 + 2^3

#10263 - tepples - Sun Aug 31, 2003 11:51 pm

Division is slow on any ARM processor, but multiplication is fast on any ARM core with the fast multiplier such as the GBA's ARM7TDMI. If the second number is small, multiplication may take only three cycles; adding, shifting, and adding may take more, especially from slow instruction memory.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#10881 - yaustar - Fri Sep 19, 2003 2:58 am

Quote:
x * 256 --> x<<8
x * 24 --> x<<4 + x<<3 explanation 24 = 2^4 + 2^3


How would you divide using bitshift? bitshift right?
_________________
[Blog] [Portfolio]

#10907 - Datch - Fri Sep 19, 2003 7:55 pm

Right.

x >> 1; // x / 2;
x >> 2; // x / 4;
x >> 3; // x / 8;

and so on... But I don't know any trick to divide by something else than a power of 2. Is it possible?
_________________
Visit SR-388 now and get a 40% discount!