Re: 2 style questions

From: Martin Ambuhl (mambuhl_at_earthlink.net)
Date: 12/21/03


Date: Sun, 21 Dec 2003 20:40:55 GMT

Sander wrote:

> 1.
> I was having a discussion with somebody and I think it's just religious.
> We are developing some software and he was looking through my code.
> I use if (pointer) to test a pointer for NULL. He says it must be if
> (p!=NULL).

"Must" is obviously wrong.

> The arguments are that it's more readable

Some people make this claim, so I believe that it is true for _them_. It
is not true for me, and, I suspect, it is not true for most experienced C
programmers.

> and that if (p) is not portable.

This is completely false. Do not take any further advice from anyone
making such obviously false statements.

[...]
> Then I started looking through his code and what I noticed that he very
> often does things like this:
>
> char *func(char **out)
> {
> *out = malloc(100);
> return malloc(10);
> }
>
> This might also be a style issue, but it's a style where it's very easy to
> introduce bugs (and indeed I found a few)
> and even more easy to introduce bugs if you don't know the internals of the
> function. So, what do you think about this style?

Failure to check the return value from malloc is much worse than a "style
issue." If this failure is in supposedly professional code, it shows
incompetence. The use of hard-coded magic numbers shows a cavalier
indifference to maintenance unbecoming a professional.

-- 
Martin Ambuhl


Relevant Pages