Bug 43114 - initializing constants from each other
initializing constants from each other
Status: CLOSED NOTABUG
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
7.1
All Linux
medium Severity low
: ---
: ---
Assigned To: Jakub Jelinek
David Lawrence
http://gcc.gnu.org/ml/gcc-bugs/2000-0...
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2001-05-31 18:01 EDT by roystgnr
Modified: 2007-04-18 12:33 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2001-05-31 18:02:44 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
minimal demonstration source code (282 bytes, text/plain)
2001-05-31 18:02 EDT, roystgnr
no flags Details

  None (edit)
Description roystgnr 2001-05-31 18:01:12 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux 2.4.2-2smp i686; en-US; 0.8.1)
Gecko/20010430

Description of problem:
gcc-2.96-81 refuses to initialize one const int with an expression
containing the value of another constant integer, exiting with the error
"initializer element is not constant".

How reproducible:
Always

Steps to Reproduce:
1.Save attached file as "testconst.c"
2."gcc -o testconst testconst.c"
3.
	

Actual Results:  testconst.c:3: initializer element is not constant

Expected Results:  Successful compilation

Additional info:

egcs-1.1.2 exits with the same error.  According to the (year old) gcc-bugs
post archived at the above URL, gcc-2.95.2 compiles this code as expected.
 I'm not 100% certain that initializing one const from another is valid
ANSI C (my copy of K doesn't bring up the problem), but I can't see why it
wouldn't be allowed.
Comment 1 roystgnr 2001-05-31 18:02:40 EDT
Created attachment 20050 [details]
minimal demonstration source code
Comment 2 Jakub Jelinek 2001-06-01 04:21:28 EDT
From my testing gcc-2.95.2 does not accept it either.
Some legalesse:
6.6.6
An integer constant expression shall have integer type and shall only have
operands that are integer constants, enumeration constants, character
constants, sizeof expressions whose results are integer constants, and
floating constants that are the immediate operands of casts. Cast operators
in an integer constant expression shall only convert arithmetic types to
integer types, except as part of an operand to the sizeof operator.
6.6.7
More latitude is permitted for constant expressions in initializers. Such a
constant expression shall be, or evaluate to, one of the following:
- an arithmetic constant expression,
- a null pointer constant,
- an address constant, or
- an address constant for an object type plus or minus an integer constant
  expression.
6.6.10
An implementation may accept other forms of constant expressions.
6.7.8.4
All the expressions in an initializer for an object that has static storage
duration shall be constant expressions or string literals.

(only included the relevant paragraphs).
As you can see, your program is not valid ISO C, but according to 6.6.10 gcc
could decide to accept it as constant expression, but it does not have to
(unlike in C++).
None of egcs 1.1.x, gcc 2.95.x, gcc-2.96-RH, gcc 3.0 or gcc 3.1 accept this.

Note You need to log in before you can comment on or make changes to this bug.