Re: [PATCH 16/16] fix handling of integer constant expressions

From: Segher Boessenkool
Date: Thu Jun 28 2007 - 05:08:45 EST


Here are three independently invalid non-ICEs that sparse doesn't
diagnose.

extern int f(void);
enum { cast_to_ptr = (int) (void *) 0 };
enum { cast_to_float = (int) (double) 1 };

Those two *really* shouldn't fail. I don't care if the C standard says so,
that is *fine*.

GCC doesn't guarantee you this, either.

In particular, "offsetof()" should be portably able to basically be the
standard #define, which involves an integer cast from a constant pointer.
That had *better* be a valid constant integer expression, because it's
very useful.

Yes it's useful. That's why GCC gives you __builtin_offsetof()
for this purpose.

And I think standards can go screw themselves, and you can make it an
error with some "--standard-pedantic" switch or similar.

Standards are just random pieces of paper, for crying out loud! They have
zero relevance in the end.

Sure, as long as you don't care about compatibility across
compilers, what matters is what the compilers you _do_ use
actually implement. And note that GCC doesn't guarantee
you much over what the C standard does. Almost everything
it allows extra is just an implementation side effect.


Segher

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/