public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c/5336: initializer element is not constant
@ 2002-04-29 18:25 rth
  0 siblings, 0 replies; 3+ messages in thread
From: rth @ 2002-04-29 18:25 UTC (permalink / raw)
  To: dima, gcc-bugs, gcc-prs, nobody

Synopsis: initializer element is not constant

State-Changed-From-To: open->closed
State-Changed-By: rth
State-Changed-When: Mon Apr 29 18:25:50 2002
State-Changed-Why:
    Not a bug.  Constant data does not a constant expression make.
    See section 6.6 of the ISO C standard.  In part:
    
    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.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5336


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: c/5336: initializer element is not constant
@ 2002-04-29 13:46 Luben Tuikov
  0 siblings, 0 replies; 3+ messages in thread
From: Luben Tuikov @ 2002-04-29 13:46 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c/5336; it has been noted by GNATS.

From: Luben Tuikov <luben@splentec.com>
To: gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org, dima@cc.hut.fi,
   gcc-bugs@gcc.gnu.org, nobody@gcc.gnu.org
Cc:  
Subject: Re: c/5336: initializer element is not constant
Date: Mon, 29 Apr 2002 16:37:05 -0400

 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5336
 
 I've reconfirmed this error on gcc 3.0.4/GNU/Linux 2.4.18/Red Hat 7.1.
 
 It is gcc's error!
 
 Here is my code:
 ---cut-----------------
 #include <stdio.h>
 
 typedef struct {
 	int i;
 	char c;
 } IC_t;
 
 const IC_t def_tic = { 'A', 'A' };
 
 static const int testme = sizeof(int) + def_tic.i;  /* gcc-gcc, where are you? */
 
 int main()
 {
 	def_tic.c = 'b';			    /* error ok */
 
 	/* threaten to use */
 	printf("def_tic.c = %c\n", def_tic.c);
 
 	return 0;
 }
 ---cut-----------------
 
 Furthermore, ``def_tic'' is put into the read-only
 section of the ELF, just as ``testme'' would be if
 it could compile it -- still gcc doesn't consider
 it and craps out.
 
 This is somewhat a severe bug, as it forces me to write
 ugly code (workarounds gcc's behavior).
 
 Please, please, fix it.
 
 -- 
 Luben


^ permalink raw reply	[flat|nested] 3+ messages in thread

* c/5336: initializer element is not constant
@ 2002-01-09  8:36 dima
  0 siblings, 0 replies; 3+ messages in thread
From: dima @ 2002-01-09  8:36 UTC (permalink / raw)
  To: gcc-gnats


>Number:         5336
>Category:       c
>Synopsis:       initializer element is not constant
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Wed Jan 09 08:36:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     dima@cc.hut.fi
>Release:        2.96 (*g*), 3.0.1
>Organization:
>Environment:

>Description:
compiler exits with error on code which is legal at least in common sense.



when comiling something like:



int * const ptr1 = (int *) 0xf0f0f0f0;

int * const ptr2 = ptr1;



compiler exits with error "initializer element is not constant", although it sorta is. it's not "a constant", but it sure is "constant".



I'll go dig C docs, if it is indeed so that init element must be "a constant expression" then a change of error message would be good.
>How-To-Repeat:
int * const ptr1 = (int *) 0xf0f0f0f0;

int * const ptr2 = ptr1;
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-04-30  1:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-29 18:25 c/5336: initializer element is not constant rth
  -- strict thread matches above, loose matches on Subject: below --
2002-04-29 13:46 Luben Tuikov
2002-01-09  8:36 dima

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 read-only IMAP folder(s) and NNTP newsgroup(s).