[Top][All Lists]

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

[Bug-gnulib] avoid using casts whenever possible [Re: gnulib/lib error.c

From: Jim Meyering
Subject: [Bug-gnulib] avoid using casts whenever possible [Re: gnulib/lib error.c
Date: Mon, 29 Sep 2003 12:34:07 +0200

Bruno Haible <address@hidden> wrote:
> Jim Meyering wrote:
>>   $ grep -E '\) *alloca\>' *.[ch]
>>   setenv.c:       new_value = (char *) alloca (namelen + 1 + vallen);
>>   vasnprintf.c:      (char *) alloca (7 + d.max_width_length + 
>> d.max_precision_length + 6);
> I still find the code more maintainable with the cast than without.
> But we have already been through this.

Don't want to beat a dead horse, but...

I think I remember you arguing that you wanted to perform pointer
arithmetic directly on the value returned by a function like alloca
or malloc.  Was that the only reason?

IMHO, casts in C make code *less* maintainable because the type of
the cast often must agree with that of a related variable, and there
is no mechanism to ensure that they stay in sync.  As such, I try
hard to avoid casts, even if that restriction induces slightly more
verbose code in a few cases.  BTW, none of the changes in gnulib
or coreutils resulted more verbose code.

Of course, if we could use gcc's __typeof__, it'd be a different
story -- at least in some cases.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]