Re: Cast abuse



On 2001.11.19 11:44:51 +0000 Brian Stafford wrote:
> On Mon, 19 November 11:32 Carlos Morgado wrote:
>> 
>> On 2001.11.19 11:18:21 +0000 Brian Stafford wrote:
>> 
>> 
>>> all a cast silences the compiler about potential coding errors.  Also 
>>> remember that void pointers eliminate the need for a lot of casts, e.g. 
>>> code like "ptr = (int *) malloc(..." is always unnecessary since malloc 
>>> returns a void *.  Just write "ptr = malloc(...".  The same goes for
>> is this C9x ? i certainly remember ansi/k&r compilers didn't allow for
>> automagic void * promotion --
> 
> AFAIK, this has been the case ever since the introduction of void to K&R C; 
> one of the motivating factors for void * was to avoid the need for casting 
> char * to the required type when it was used as a generic pointer type.  I 
> certainly have never come across a compiler that requires the cast, ANSI or 
> K&R+void.  Not even any of the M$ C compilers, despite the M$ penchant for 
> polluting code with casts at every opportunity.
> 
i'm fairly sure CC that came with osf/1 3 wanted it. i might just have cargoed
it since back when.
i may also be confusing lvalues and pointer arithmetic ... go figure

> Indeed, if a void pointer could not be freely assigned or compared, it 
> would not offer any advantage over the use of char pointer as a generic 
> pointer type.
> 
true

cheers

-- 
Carlos Morgado - chbm(at)chbm(dot)nu - http://chbm.nu/ -- gpgkey: 0x1FC57F0A
http://wwwkeys.pgp.net/ FP:0A27 35D3 C448 3641 0573 6876 2A37 4BB2 1FC5 7F0A
Software is like sex; it's better when it's free. - Linus Torvalds



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]