2 style questions

From: Sander (i_at_bleat.nospam.com)
Date: 12/21/03


Date: Sun, 21 Dec 2003 08:48:45 +0100

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).
The arguments are that it's more readable and that if (p) is not portable.
I said the first is a style issue and that I think if(p) is more readable
and that the second is plain wrong.

So, is he right about the portability issue? is if (p) not strictly correct
C code?

2.
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?



Relevant Pages

  • Re: 2 style questions
    ... Sander wrote: ... > I use if (pointer) to test a pointer for NULL. ... is he right about the portability issue? ... > and even more easy to introduce bugs if you don't know the internals of the ...
    (comp.lang.c)
  • Re: 2 style questions
    ... > I use if (pointer) to test a pointer for NULL. ... is he right about the portability issue? ... programming oriented editors let you jump right to the declaration. ... > and even more easy to introduce bugs if you don't know the internals of the ...
    (comp.lang.c)
  • Re: Please Help ----------Free Downloadable Ebooks for C 
    ... here are the next half-dozen bugs for you. ... Medium nit: For int fnon page 18, you claim that a is an argument. ... compilers exist which pre-date C99 and for which their ... pointer. ...
    (comp.lang.c)
  • Re: large files (> 4GB) ... when will they be ubiquitous?
    ... |> The reason I see for this is that Linux tried to maintain ABI compatibility ... But said code isn't written to use the correct data types that would ... | high bit of a pointer will be zero. ... | The problem is basically that code has bugs. ...
    (comp.os.linux.development.system)
  • Re: Finding user/kernel pointer bugs [no html]
    ... applied to a pointer - that's it, ... a code that reads long from userland, casts it to pointer and dereferences ... It's a different problem and a different class of bugs. ... Note that casts ...
    (Linux-Kernel)