Re: Best way of clearing a compiler warning?



At about the time of 11/6/2005 8:54 PM, Keith Thompson stated the following:

> Ben Pfaff <blp@xxxxxxxxxxxxxxx> writes:
>
>>Daniel Rudy <spamthis@xxxxxxxxxxxx> writes:
>
> [...]
>
>>>Here's my command line:
>>>
>>>gcc -W -Wall -Wshadow -Wpointer-arith -Wcast-align -Wstrict-prototypes
>>>-Wmissing-prototypes -Wnested-externs -Wwrite-strings -Wfloat-equal
>>
>> ^^^^^^^^^^^^^^^
>>There you go. If you remove that, your original code should
>>compile free of that particular warning.
>>
>>
>>>-Winline -Wtrigraphs -pedantic -ansi -std=c89 -ggdb3 -I.. -lm -lmd -lc
>>>-lcrypto -o digest.test digest.test.c digest.c ../sha2.c ../error.c
>>>../syslog.c
>
>
> Yes, but it's a good warning.
>
> Here's an inexact summary of the code in question:
>
> void error(char *errmsg, int code);
> ...
> error("This is an error message", errno);
>
> Given this, the compiler can't tell whether error() modifies the
> string passed to it. If it could analyze the actual implementation of
> the error() function, it could safely refrain from warning about the
> use of a string literal.
>
> The best way to handle this is for the error() function to promise not
> to modify the string that its argument points to; the compiler than
> then warn about calls that might potentially violate that promise.
>

FWIW, the reason why I specify the warnings that I do is to force me
into writing clean, conforming, and correct code that will compile and
run on the widest number of systems out there with any problems. Right
now, my code will work on *BSD systems and possibly Linux as well, but
this is a platform issue, not a C issue.

--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
.



Relevant Pages