[Top][All Lists]

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

Re: [Tinycc-devel] match formats and arguments exactly

From: ian
Subject: Re: [Tinycc-devel] match formats and arguments exactly
Date: Fri, 21 Jun 2019 16:10:55 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101 Thunderbird/52.9.1


IMHO, considering that flexibility is what I love in C programming, and that this checking should be printf job (in that case), and many other things, I agree with Christian.
Even more, still IMHO, a pointer is a pointer, no matter actually how it will be interpreted later.


-- ian (address@hidden)
-- développeur compulsif
Le 21/06/2019 à 15:33, Christian Jullien a écrit :

If I read you correctly, you want to protest if type does not strictly match format directive.


This is something even gcc does NOT ensure by default:


#include <stdio.h>

#include <stdlib.h>



main() {

        int i = 256;

        const char* s = "Hello";

        const void* p = s;


        printf("%x\n", i);

        printf("%u %s\n", i, p);




$ gcc -std=c11  foo.c

$ => Ok


Only -Wformat (or -Wall) shows a warning on the 2nd printf, printf of i (a signed) is always Ok.


$ gcc -std=c11 -Wall foo.c

foo.c: In function 'main':

foo.c:11:21: warning: format '%s' expects argument of type 'char *', but argument 3 has type 'const void *' [-Wformat=]

         printf("%u %s\n", i, p);                                                                   ~^                                                                              %p       


-----Original Message-----
From: Pascal Cuoq [mailto:address@hidden]
Sent: Friday, June 21, 2019 15:17
To: address@hidden; address@hidden
Subject: Re: [Tinycc-devel] match formats and arguments exactly



> On 21 Jun 2019, at 14:56, Christian Jullien <address@hidden> wrote:


> This is a valuable check but IMHO, it should be controlled by -Wformat (as

> GNU gcc) and set of false by default.

> Otherwise, I suspect tcc users will have a lot a new warnings.


I'm not implementing a new warning in TCC. I am only ensuring, by following C11 to the letter, that the TCC source code passes the strictest such checks that a C compiler could have, and also that a very exotic C compiler does not produce a non-functional binary when compiling TCC.


Considering the amount of code that good warnings represent, I think that a C compiler can either be tiny, or provide helpful warnings. The patches I have been sending, including the last one, only make TCC not exhibit undefined behavior, a more manageable goal that only requires small changes and do not make TCC significantly larger.



Tinycc-devel mailing list

reply via email to

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