News for hackers. Stuff that matters.
Re:Simple Dynamic Strings library for C by simias on Thursday February 06, 2014 @11:04AM (#7190996)
Heh, you're the first person I meet who advocates dropping the parens around the sizeof argument in any situation. That does look terribly alien to me.
Re:Simple Dynamic Strings library for C by breadbox on Thursday February 06, 2014 @12:33PM (#7191594)
Really? I always do. If you don't, it makes the variable look like a type. It's the same reason why I dislike extra parens around the value in the return statement. Don't make it look like something it isn't.
Re:Simple Dynamic Strings library for C by adestefan on Thursday February 06, 2014 @12:39PM (#7191640)
sizeof is a unary operator and not a function. Only types need to be enclosed in parens. Most people don't know this.
Re:Simple Dynamic Strings library for C by unwind on Friday February 07, 2014 @03:45AM (#7195354)
Exactly! For some reason this anti-pattern is very thoroughly entrenched among C programmers and it's so very frustrating.

My other favorite is casting the return value of malloc(), something you see a great deal of and that I always oppose. See http://stackoverflow.com/questions/605845/do-i-cast-the-resu... for my best arguments.

Re:Simple Dynamic Strings library for C by Narishma on Friday February 07, 2014 @10:54AM (#7196800)
Casting the return value of malloc is necessary in C++. I think that's why it's so widespread, so you can compile your C program with a C++ compiler.