Re: [C] freeing memory allocated in a function

From: Arthur J. O'Dwyer (ajo_at_nospam.andrew.cmu.edu)
Date: 05/31/04


Date: Mon, 31 May 2004 12:01:19 -0400 (EDT)


On Tue, 1 Jun 2004, Chris ( Val ) wrote:
>
> "Arthur J. O'Dwyer" <ajo@nospam.andrew.cmu.edu> wrote...
> |
> | On Sun, 30 May 2004, Marlene Stebbins wrote:
> | > xy = malloc(2 * sizeof(*xy));

> | the extra parentheses are... well... extra! Remove them.
>
> That may be so in this case, but, they(the parentheses),
> are required when evaluating built in types, so it's not
> a real bad habit to get into, I think.

  Maybe this is a C++ thing, or maybe it's an acllcc++ thing.
In comp.lang.c, the general wisdom is to omit needless syntax
when it doesn't help to clarify anything; "C is not Lisp." :)
  I would think that in C++, the parentheses would be especially
annoying; you would no longer be able to tell at a glance whether
'sizeof (foo)' in isolation[1] was taking the size of an object
named 'foo' or a defined type named 'foo'. When the two are
consistently written respectively 'sizeof foo' and 'sizeof (foo)',
there is no possible confusion.

  OTOH and FWIW, I myself engage in "habit-forming" ["cargo-cult"]
programming in a different area: I routinely write '++i' instead
of 'i++' in both C and C++, no matter the type of 'i', even though
it only accomplishes anything if 'i' is a class type in C++.

-Arthur

[1] - Not that you ever see 'sizeof' in isolation, so it's
not a really strong argument.



Relevant Pages