Some programming lessons learned

in C

  • Always make sure that the parameters that are passed to a function and the variables that are dealing with the parameters are always of the same type (including qualifiers) (get an unsigned long and add all of them in a signed long)
  • Initialize the dynamically allocated structures. They contain a lot of crap.
  • When using library functions make sure you know the behavior of the function and that the parameters being passed are appropriate. (using strncmp for comparing hex strings – a stupid thing to do)
  • Don’t have presumptions about the code – that some part is correct and some is not. It becomes difficult to debug them.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s