Re: C99 Question
From: pete (pfiland_at_mindspring.com)
Date: 12/30/03
- Next message: Peter : "Re: explanation of a program required please"
- Previous message: pete: "Re: Arrays of Strings, malloc"
- In reply to: Vijay Kumar R Zanvar: "C99 Question"
- Next in thread: Martin Ambuhl: "Re: C99 Question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 30 Dec 2003 11:39:49 GMT
Vijay Kumar R Zanvar wrote:
>
> Hi,
>
> Which section of C99 says that return value
> of malloc(3) should not be casted?
How about an errata from K&R2 instead ?
142(§6.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.
http://cm.bell-labs.com/cm/cs/cbook/2ediffs.html
-- pete
- Next message: Peter : "Re: explanation of a program required please"
- Previous message: pete: "Re: Arrays of Strings, malloc"
- In reply to: Vijay Kumar R Zanvar: "C99 Question"
- Next in thread: Martin Ambuhl: "Re: C99 Question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|