@
technologist
Well I screwed up with my earlier advice, but if you have cottoned on to using a debugger, then that's awesome.
I guess one eventually develops a sort of self reliance: Being able to fix one's own problems; knowing where to look to find out etcetera. I am sure in production code houses, one is not expecting (or making) a visit to say: "My code doesn't compile, what have I done?". However, there is so much stuff to learn. But if one can take the attitude of nutting out their own problems by always reading the documentation for things they are using, research with Google or Wiki, and try different things, then that puts one well on the way to being a good coder IMO.
Also, I think it is healthy to make some mistakes, as long as one remembers what the cause and fix were. Now that you are aware of the pesky semicolon, you are probably unlikely to make that mistake again. I always put an opening brace after any loop or if statement, by force of habit. These days my editor does the closing brace for me.
There are some (hopefully rare) situations where a null statement
is required, and it is good practise IMO to comment it. For example, in K&R C Programming (Ch 5 p88), they have strcpy like this:
1 2 3 4 5 6
|
/* strcpy copy string t to string s*/
void strcpy(char *s, char *t)
{
while( *s++ = *t++)
;
}
|
I prefer to do this, so one would definitely not miss the null statement:
1 2 3 4 5 6 7
|
/* strcpy copy string t to string s*/
void strcpy(char* s, char* t)
{
while( *s++ = *t++) { /* always use braces, even for 1 statement */
; /* null statement */
}
}
|
It's quite instructive to see how they started out with this, then boiled it down to this essentially one liner.
Here is a link to K&R, hopefully it won't hurt your c++ skills - it's a completely different way of thinking.
http://zanasi.chem.unisa.it/download/C.pdf