Home > Coding > This is why I don’t like C…

This is why I don’t like C…

Had to write some C (arghhh…). Simple test of a return code from a function call with zero being OK and anything else being a failure. So I coded:

if (!rc) {do failure code...}

Now to me, that says, if the return code is not good, do the failure code which is what I wanted. So I was happy until someone pointed out that in C, zero is false and anything else is true so basically my logic was backwards.

In the end I went with the more specific and exact:

if (rc != 0) { etc….

Any language that is this easy to screw up is basically flawed in my opinion. No wonder we have so many software problems in the world!

Advertisements
Categories: Coding
  1. No comments yet.
  1. No trackbacks yet.

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

%d bloggers like this: