[Nut-upsdev] gcc4 compiler warnings

Peter Selinger selinger at mathstat.dal.ca
Fri Feb 10 14:31:49 UTC 2006


Arjen de Korte wrote:
> > Changing the prototypes of these functions to use "unsigned char *buf"
> > instead of "char *buf" will have _no effect whatsoever_ on the drivers
> > that call there functions.
> 
> I just realized the same. But there is a better way to make the compiler
> shut up about these warnings, by defining these buffers as 'void *'
> instead of 'char *' like:
> 
> int ser_send_buf(int fd, const void *buf, size_t buflen);
> int ser_get_char(int fd, void *ch, long d_sec, long d_usec);
> int ser_get_line(int fd, void *buf, size_t buflen, char endchar,
>    const void *ignset, long d_sec, long d_usec);
> int ser_get_buf_len(int fd, void *buf, size_t buflen, long d_sec,
>    long d_usec);

I am against this. In principle, compiler warnings are a good thing
(for example, try applying one of the above functions to (int *)).  

I believe the type (void *) should only be used for data whose value
is intended to be typecast (such as malloc()), or where the nature of
the data truly does not matter (such as memset()).

I just tried, experimentally, to replace the types in the above
functions (and a few of their friends) by (unsigned char *), and while
this increased the compiler warnings, this is primarily due to the
fact that several of the drivers were explicitly converted to (char *)
this morning. If there is no opposition, I will commit the changes
later (and I will only do the "benign", i.e., pointer, changes; will
leave it up to driver maintainers to decide if they want to use "char"
or "unsigned char" internally).

-- Peter



More information about the Nut-upsdev mailing list