Re: Cast abuse
- From: Toralf Lund <toralf kscanners com>
- To: Brian Stafford <brian stafford uklinux net>
- Cc: Balsa List <balsa-list gnome org>
- Subject: Re: Cast abuse
- Date: Mon, 19 Nov 2001 17:08:35 +0100
On 19/11 2001 12:18 Brian Stafford wrote:
> Just pulled the latest balsa from CVS and got problems compiling
> address-book-ldap.c. The problem is that casts are used to abuse const
> strings. Fortunately gcc catches this nonsense and warns about it.
>
> <rant>
> As a general point, I feel that when programming in C, if a cast is
> used, something is wrong in the code. All reasonable efforts should be
> made to rewrite the code avoiding the cast. Use casts only as a last
> resort, after 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 comparisons with void pointers, forget
> the cast.
> </rant>
Can the str...() declarations be assumed to use "const" properly on all
platforms? I seem to remember that _all_ string arguments had type "char
*" on some of our systems in a not-to-distant past.
- Toralf
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]