Re: Pointer dereference rather than sizeof?
- From: Richard<rgrdev@xxxxxxxxx>
- Date: Thu, 28 Aug 2008 16:53:37 +0200
rlb@xxxxxxxxxxxxxxxxxxxxxx (Richard Bos) writes:
Peter Nilsson <airia@xxxxxxxxxxx> wrote:
<http://www-db-out.research.bell-labs.com/cm/cs/cbook/2ediffs.html>
Quote:
142(S6.5, toward the end): The remark about casting the
return value of malloc ("the proper method is to declare
... then explicitly coerce") needs to be rewritten. The
example is correct and works, but the advice is debatable
in the context of the 1988-1989 ANSI/ISO standards. It's
not necessary (given that coercion of void * to
ALMOSTANYTYPE * is automatic), and possibly harmful if
malloc, or a proxy for it, fails to be declared as
returning void *. The explicit cast can cover up an
unintended error. On the other hand, pre-ANSI, the cast
was necessary, and it is in C++ also.
It's surprising how some people seem to have interpreted
"The example is correct and works" as somehow meaning the
example is incorrect and doesn't.
Not quite as surprising as the number of people who read "needs to be
rewritten" as "is more than correct and should be followed by
everybody".
Richard
What is more surprising is how many people here tell fibs to enhance
their clique status as Hathfield wannabes. The old "I have never seen
that" remarks seen so often are simply lies from anyone who has worked
in industry because so much code is NOT Ansi C. As for the potential for
error from putting the cast in. since the implementation provides the
malloc in 99.9999999999999999999999999999% of instances there really is
not issue since it will be correctly prototyped.
.
- Follow-Ups:
- Re: Pointer dereference rather than sizeof?
- From: Richard Tobin
- Re: Pointer dereference rather than sizeof?
- References:
- Pointer dereference rather than sizeof?
- From: Micheal Smith
- Re: Pointer dereference rather than sizeof?
- From: Martin Ambuhl
- Re: Pointer dereference rather than sizeof?
- From: Peter Nilsson
- Re: Pointer dereference rather than sizeof?
- From: Keith Thompson
- Re: Pointer dereference rather than sizeof?
- From: Peter Nilsson
- Pointer dereference rather than sizeof?
- Prev by Date: Re: Environmental limits
- Next by Date: Re: Pointer dereference rather than sizeof?
- Previous by thread: Re: Pointer dereference rather than sizeof?
- Next by thread: Re: Pointer dereference rather than sizeof?
- Index(es):
Relevant Pages
|