* gcc-3.4.4-20050211: maybe a danger behaviour
@ 2005-02-26 18:42 Denis Zaitsev
0 siblings, 0 replies; only message in thread
From: Denis Zaitsev @ 2005-02-26 18:42 UTC (permalink / raw)
To: gcc, linux-gcc
Consider the following example:
enum w {
// c=-1,
a,
b
};
whattodo (
char option
) {
static
struct todo {
enum w what;
char option;
} todos[]= {
{a,'a'},
{b,'b'},
{-1}
};
struct todo *p= todos;
do if (
(option && !option)
) break;
while ((++p)->what >= 0);
return p->what;
}
Compiling with -O[>0] and -Wall for x86 we have that code for
whattodo:
whattodo:
.L2:
jmp .L2
a) Formally, the code is correct. As p->what can never be < 0
according to its type.
b) GCC _silently_ allows the {-1} initialization for that type, even
with -Wall.
Uncommenting the c= -1 member of enum, or explicit casting p->what to
int solves the problem, of course. But maybe some warning would be
appropriate in such a situation? It takes some time for me to
recognize what leads me to that cool .L2: jmp .L2 from seemengly
harmless C code... Or maybe I don't know some healthy compiler
option?
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-02-26 18:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-26 18:42 gcc-3.4.4-20050211: maybe a danger behaviour Denis Zaitsev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).