[Top][All Lists]

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

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

From: Vincent Lefevre
Subject: Re: [Tinycc-devel] match formats and arguments exactly
Date: Fri, 21 Jun 2019 18:49:34 +0200
User-agent: Mutt/1.12.1+19 (078654a4) vl-117499 (2019-06-15)

On 2019-06-21 15:33:24 +0200, Christian Jullien wrote:
> 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:

This is undefined behavior, and the compiler is not required
to complain. This can just mean that your code will silently
be compiled in an unexpected way.

>         int i = 256;
>         const char* s = "Hello";
>         const void* p = s;
>         printf("%x\n", i);
>         printf("%u %s\n", i, p);

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

I don't think this is correct for i as int and unsigned int are not
compatible types... even though 256 has the same representation as
int and unsigned int (I think that the C standard should have been
more flexible in such a case).

Vincent Lefèvre <address@hidden> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

reply via email to

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