On 12/06/2008, at 8:31 AM, James Rich wrote:

This really needs a cast to be proper:

s1 = (char) malloc (sizeofbuffer * sizeof(char));

Actually that's worse than not mentioning casts at all. In this case the cast should be (char*) otherwise you'll get "Operation between types unsigned char * and unsigned char not allowed". Given that Lim is having trouble with basic concepts let's not confuse him with casting.

The cast isn't necessary anyway. malloc returns a void* which is a pointer of any type. Any pointer type can be cast to void* and back without loss of information. Therefore the compiler will perform an implicit cast for you--one of the few things the compiler does to help so you might as well take advantage of it. Besides, code full of casts is uglier than necessary.


Regards,
Simon Coulter.
--------------------------------------------------------------------
FlyByNight Software OS/400, i5/OS Technical Specialists

http://www.flybynight.com.au/
Phone: +61 2 6657 8251 Mobile: +61 0411 091 400 /"\
Fax: +61 2 6657 8251 \ /
X
ASCII Ribbon campaign against HTML E-Mail / \
--------------------------------------------------------------------




This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available here. If you have questions about this, please contact [javascript protected email address].