This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
C constant expressions proposals
- From: "Joseph S. Myers" <jsm at polyomino dot org dot uk>
- To: gcc at gcc dot gnu dot org
- Date: Wed, 11 Aug 2004 00:28:04 +0000 (UTC)
- Subject: C constant expressions proposals
I have now prepared detailed semi-formal models of the interpretation of
the C constant expression rules, and their extension to GNU C, along with
ordinary English text descriptions of those extensions to constant
expressions that are de facto present in GNU C (as part of the present
"whatever the compiler of the day happens to fold to a constant is
constant") and which seem likely to have been widely used or the
preservation of which has been specifically requested in past discussions
of constant expressions. Also included are some notes on the benefits
naturally associated with implementation of well-defined constant
expression rules, apart from better conformance.
http://www.srcf.ucam.org/~jsm28/gcc/#const
Feedback welcome on these models; the (newly revised and expanded)
discussion of problems with constant expression rules in C99; the
particular extensions that should be accepted in GNU C; and anything else
about these proposals.
These proposed models would render invalid the much-discussed
gcc.c-torture/compile/20010327-1.c when pointers and longs are different
widths. I don't have a plausible description in language standard terms
of what cases should be acceptable otherwise. Note that very similar to
the case
static unsigned long x = (unsigned long) &_text - 0x10000000L - 1;
of that testcase, you could force either sign or zero extension of the
pointer plus an arbitary offset, e.g.
static unsigned long x = (unsigned long) ((uintptr_t)&_text + 123) + 456;
static long y = (long) ((intptr_t)((uintptr_t)&_text + 123)) + 456;
all of which look like extending an address constant to a wider type, then
adding a constant, but I don't know if all these cases will work when one
does.
Relevant past discussions to this testcase and constant expressions
include the following. (Representative messages from each thread only
included; broken mailers may mean not everything is linked in to the
thread; and in some cases threads may cross month boundaries.)
http://gcc.gnu.org/ml/gcc-patches/2000-11/msg00678.html
http://gcc.gnu.org/ml/gcc-patches/2001-11/msg01191.html
http://gcc.gnu.org/ml/gcc-patches/2003-02/msg01153.html
http://gcc.gnu.org/ml/gcc-patches/2003-03/msg00023.html
--
Joseph S. Myers http://www.srcf.ucam.org/~jsm28/gcc/
jsm@polyomino.org.uk (personal mail)
jsm28@gcc.gnu.org (Bugzilla assignments and CCs)