stupid google -->

Tuesday, May 22, 2007

From Java to C/C++ oh the pain the pain

Learning C from Java is tough, alot of things you take
for granted in Java cannot be found.


I had to code out my own tokeniser, though after
spending that effort I realised that actually C does
have a tokeniser in the form of strtok


sighz



Also the error catching, say if I code a method with a
return type, if I do not return, barring an IDE I
would see a memory error. I actually could'nt figure
out what was wrong until I ran VS 2003 on the code. VS
told me that the error was that I did not return. DUH!
javac would have told me that.

Still that was technical laziness on my part due to
years of using Java than the fault of C.

And I actually did learn.


For instance the throwing of the SIGSEGV interrupt
signal. It is a segmentation fault thrown by
applications when the application tries to access an
area of unallocated memory. In this case the program I
wrote tried to return but could'nt.


Ah well.


Another stumbling block was the new keyword. In Java
all objects are created via new. new calls the
constructor. In C++ new is the new malloc. (not really
but it goes on the heap as well).

That caught be for so long until I read code and saw:


new int


then it struck me that new is just allocating memory.
Not a keyword specific to objects.



It is painful making these novice mistakes, but I
think I remember the lessons better!!
-->
Clear | Activate AJAX Google Search | |
Firefox 2
Support Wikipedia