Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

1. Non-terminated comment

Use a sane editor with syntax highlighting.

2. Accidental assignment/Accidental Booleans

I always wrap my assignment-conditionals with double parentheses. It sucks when you miss these but I usually type out the right sequence of equal signs when I mean equality.

3. Unhygienic macros

Treat macros like a search-and-replace with a little more intelligence, but respect how literally the pre-processor might take you for. So, add parentheses.

4. Mismatched header files

I've not encountered this before, so I can't comment on it. Be careful with namespaces.

5. Phantom Returned Values

Luckily, gcc -Wall returns: warning: control reaches end of non-void function

6. Unpredictable struct construction

Can't comment on this one either, although I avoid literal assignments given in the example like the plague.

7. Indefinite order of evaluation

The example code just looks messy.

8. Easily changed block scope

Always use curly braces, that's what I say.

9. Permissive compilation

Not sure in the example why one would just remove the CALLIT macro and assume things to work. Of course, the comma in C means something. Not sure why one would put an assignment before a case in a switch either.

10. Unsafe returned values

This is certainly expected!



Yes, the points he makes are typical beginner mistakes, or at least things that 20 years of programmer conventions have found a way around. Not really big problems of the language.

My biggest gripe with C is string handling. Although the extremely insecure functions have been slowly phased out (such as gets), zero-terminated strings are an attack on sanity.


"My biggest gripe with C is string handling. Although the extremely insecure functions have been slowly phased out (such as gets), zero-terminated strings are an attack on sanity."

There are some nice safe string libraries out there, like this one:

http://bstring.sourceforge.net/


Agreed, it is pretty easy to avoid the issue by using a library or framework, and bstring looks nice.

Still, I wish something like that was simply built-in, as external string libraries can cause interoperability issues: Each framework defines its own string handling functions and format, making it neccesary to convert between them in an application, if you use them together.

(the worst thing is that this problem still exists with C++ as of today, even though it has a built-in string people insist on rolling their own)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: