Re: void * vs char *
Francine.Neary@ googlemail.com wrote:
You said "I still need to explicitly cast p to a (struct s*) to avoid a
compile-time error", which I showed by example to be incorrect. That's
the thing with a void*, you can use implicit conversion. What harm does
a temporary pointer cause?
Keith answered this better than I could.
--
Ian Collins.
Francine.Neary@ googlemail.com wrote:
>
>>
> struct s *ps = p;
>
A rose by any other name... I don't see that this gains anything in
terms of clarity or brevity over "printf("%d\n", ((struct s*)p)->a);" -
in fact it just leads to an additional pointer floating around.
>
>>>void call(void *p)
>>>{
>> printf("%d\n",p->a);
>>>{
>> printf("%d\n",p->a);
> struct s *ps = p;
A rose by any other name... I don't see that this gains anything in
terms of clarity or brevity over "printf("%d\n", ((struct s*)p)->a);" -
in fact it just leads to an additional pointer floating around.
>
compile-time error", which I showed by example to be incorrect. That's
the thing with a void*, you can use implicit conversion. What harm does
a temporary pointer cause?
>
>
As this conversion is lossless, I don't see why the compiler should
take it upon itself to warn me about it!
>
>>Now change call to
>>
>>void call( char* );
>>
>>And see what your compiler has to say. If you don't get two
>>incompatibl e type warnings, you haven't turned your warning level high
>>enough.
>>
>>void call( char* );
>>
>>And see what your compiler has to say. If you don't get two
>>incompatibl e type warnings, you haven't turned your warning level high
>>enough.
As this conversion is lossless, I don't see why the compiler should
take it upon itself to warn me about it!
>
--
Ian Collins.
Comment