GP32 Java....


The only languages I have been taught in school (second yr tech school currently) have been VB6, VB.Net, Cobol, ASP, JS, and Java (and of course markup languages). Not once have i been taught C/C++. But, i have been writing Java for many years now, and my transition to learning C++ has been quite easy.
 
If you're in university, you must learn C. Too many people are graduating without understanding basic tenets of software development, like "strings are slow" and pointer arithmetic.
 
If you're in university, you must learn C. Too many people are graduating without understanding basic tenets of software development, like "strings are slow" and pointer arithmetic.
Okay, wtf is pointer arithmetic?! :lol:

Edit: I see, can anyone give me a real-life example of what this would be used in. Lots of this stuff I just can't see a use for when I read it.
 
Last edited by a moderator:
If you're in university, you must learn C. Too many people are graduating without understanding basic tenets of software development, like "strings are slow" and pointer arithmetic.
Okay, wtf is pointer arithmetic?! :lol:

Edit: I see, can anyone give me a real-life example of what this would be used in. Lots of this stuff I just can't see a use for when I read it.
One good example is REALLY fast array transversing. Usually a lot of new programmers will use for loops to tranverse an array eg

Code:
char test_data[1000];
for ( int a = 0; a < 1000; a++)
 test_data[a] = 'b';

This is actually quite slow since it uses an instruction to access the variable, another instruction to get to the correct place (in memory) in the array and another to read the variable a.

[note: not 100% sure on the number of instructions but you get the general idea]

With pointers you do [i thnk, code not tested]
Code:
char test_data[1000];
char *ptr = &test_data[0]; // point to the beginning of the array
for (int a = 0; a < 1000; a++)
{
 *ptr = 'b';
 ptr++;
}

Now you are using only one instruction to access the correct area of memory for the array. You are using another for ptr++ but you can easily change the conditional so that it does ptr++ instead a++ and perform the correct test but I cant remember how off the top of my head.

So in total you are saving 2000 instruction calls in that loop alone out of the original 3000 (66% speed increase).

In fact, here is where someone else taught me:
http://forum.gbadev.org/viewtopic.php?t=2305&highlight=radar
 
Last edited by a moderator:
Java and C share quite a few similarities.
So your University Java Course might come in handy!
ermm.. yes. and no.
java looks like C++, but it works in a whole different way underneath. Doesn't matter for simple stuff, but once you get into anything more advanced its good to fully understand how each of them work, and it can make a BIG difference.

It is definitely worth learning a bit about C++ in my opinion, if you get the opportunity.
 
Last edited by a moderator:
Back
Top