[cfe-dev] The %p conversion and cast to void*

Seth Cantrell seth.cantrell at gmail.com
Tue Feb 24 09:50:45 PST 2015


It seems reasonable for this kind of warning to go under some -pedantic flag, something like "-Wformat-pedantic".

> On Feb 24, 2015, at 12:31 PM, David Chisnall <David.Chisnall at cl.cam.ac.uk> wrote:
> 
> On 21 Feb 2015, at 03:56, Rouben Rostamian <rostamian at umbc.edu> wrote:
>> 
>> My question is: Why is it that removing the cast /does not/
>> trigger a warning in Clang?  Do I need to specify further
>> compilation flags to get that warning?
> 
> It used to generate a warning in clang but it was spectacularly annoying and so was removed because it generated a huge number of false positives.  The C standard does require that the argument for %p 'be a pointer to void', but the only platforms where any other data pointer (in the same address space) would be problematic are ones that do not natively support byte addressing and so need different pointer types for char* and void* and anything word aligned.  Clang does not support any such architectures and a lot of C code that people compile with clang / gcc would break on such architectures.
> 
> The choice is to either have a warning that you are violating the letter of the C spec, but that your code will still work on every platform that you're likely to ever care about (and I say this as someone working on an architecture with a very unusual pointer representation, for which this warning would *still* be a false positive), or to allow this code through.
> 
> Clang policy is that good code ought to be able to use -Wall -Werror by default, because warnings that have too high a false positive rate are not present.  If warnings are too likely to produce false positives (i.e. flag things that work fine on every system where the code is plausibly likely to run), then it doesn't help the programmer, it just makes them turn off the warning.
> 
> David
> 
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev





More information about the cfe-dev mailing list