Re: is const necessary in eg int compar(const void *, const void *)
Richard Tobin said:
Mr Twink is wrong on technical grounds and sub-optimal on stylistic
grounds: firstly, you *don't* need a cast, and secondly, "explicit" is
redundant.
Yes. I don't think anyone has claimed otherwise.
>
Alternatively the implementor can provide a macro for a format string,
as C99 does (PRIdMAX etc).
Yes. But if the type is opaque and not supported by the implementation, the
cast is in any case unwise. Instead, you should pass the value to the
opaque type's stream-writing function.
--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Richard Tobin said:
In article <slrngfc37b.e4q .nospam@nospam. invalid>,
Antoninus Twink <nospam@nospam. invalidwrote:
>
>
I'm sure someone will point out how it *can* be done without a cast,
Antoninus Twink <nospam@nospam. invalidwrote:
>
>>1) When passing a NULL pointer to variadic functions, you need an
>>explicit cast, e.g.
>>s = mystrconcat("he llo", " ", "world", "!", (char *) NULL);
>>explicit cast, e.g.
>>s = mystrconcat("he llo", " ", "world", "!", (char *) NULL);
I'm sure someone will point out how it *can* be done without a cast,
grounds: firstly, you *don't* need a cast, and secondly, "explicit" is
redundant.
but of course a cast is the natural way to do it.
>>2) If you have a type that you know is an integer type but is typedef'd
>>in a system-specific header, then to portably print it you need a cast
>>to the widest integer type:
>>
>>opaque_intege r_type i = somefunction(42 );
>>printf("The answer is %llu\n", (unsigned long long) i);
>>in a system-specific header, then to portably print it you need a cast
>>to the widest integer type:
>>
>>opaque_intege r_type i = somefunction(42 );
>>printf("The answer is %llu\n", (unsigned long long) i);
Alternatively the implementor can provide a macro for a format string,
as C99 does (PRIdMAX etc).
cast is in any case unwise. Instead, you should pass the value to the
opaque type's stream-writing function.
--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Comment