Sujet : Re: "undefined behavior"?
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 14. Jun 2024, 21:43:28
Autres entêtes
Organisation : None to speak of
Message-ID : <87zfrn45n3.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Keith Thompson <Keith.S.Thompson+
u@gmail.com> writes:
[...]
I don't know. The default gcc on my system diagnoses it by default, but
various versions of gcc I've built from source do not. Perhaps Ubuntu
configures gcc differently. (Ubuntu 22.04.4, gcc 11.4.0.) I'm building
gcc 11.4.0 from source, and I'll compare its behavior to that of
Ubuntu's gcc 11.4.0-1ubuntu1~22.04.
[...]
Context: Warning about incorrect printf format strings, such as
`printf("%d\n", strlen(s));` ("%d" requires an int argument but strlen()
returns a result of type size_t).
I've confirmed that, on my Ubuntu 22.04 system, the system-provided
gcc ("Ubuntu 11.4.0-1ubuntu1~22.04") warns about the mismatch, but
gcc 11.4.0 built from source does not.
So Ubuntu (or its upstream Debian) does a custom build of gcc that
enables "-Wformat" by default.
Confirmed by this answer on Stack Overflow:
<
https://stackoverflow.com/a/50112401/827263>
"""
This is not caused by a difference in GCC versions. Rather, Ubuntu has
modified GCC to enable -Wformat -Wformat-security by default. If you
pass those options on Arch Linux, you should see the same behaviour
there.
"""
(The answer contains a link to a web page that no longer exists.)
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */