I don't think that what you said is exactly true. It should be "Don't Post C until you understand the language first.
Mr Ekted - Tue Mar 02, 2004 12:08 am
Post subject:
No. I meant don't use it. Every time there's a thread about something to do with code, half the people are just taking guess about how the language works, and some of them are actually trying to make stuff. How about read a book first?
50% Packetloss - Tue Mar 02, 2004 2:33 am
Post subject:
I didnt read much, just pointing out a small thing that bugs me.
Do NOT do if(blah){return true;} else {return false;} . This is ghey and you need to just make a variable. bool Bob=false; and if the function turns out to be true, make bob=true; and then return bob; at the end of the function. Placing returns in the middle of functions is confusing. A bool is 1 byte large, it will be a lot less hassle to just declare the variable and then return it at the end of the function.
Mr Ekted - Tue Mar 02, 2004 3:05 pm
Post subject:
Agreed. Never return in the middle of a function. It is wrong, and can lead to nasty bugs like resource/memory leaks, unclosed files, etc.
Also, if you want to be picky, int is better than bool. It is much faster under Intel (Windows, Linux) to read/write a full 32-bit value than an 8-bit value. Using bool saves data space if there are thousands of them as public/static data, but on the stack they pretty much have no benefit.