public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* To const or not to const...
@ 2003-02-20 14:27 Jan-Benedict Glaw
  2003-02-20 16:21 ` Christian Ehrhardt
  0 siblings, 1 reply; 6+ messages in thread
From: Jan-Benedict Glaw @ 2003-02-20 14:27 UTC (permalink / raw)
  To: gcc

[-- Attachment #1: Type: text/plain, Size: 888 bytes --]

Hi!

After playing a bit with macros, I came to some construct I don't fully
understand (or gcc does something bad with it. Here's my testcase:

int a = "hello"[2]; /* #1 */
int main() {
	int b = "again_hello"[5]; /* #2 */
	return 0;
}


Assignment #2 is okay from GCC's eyes, but #1 isn't:

t2.c:2: initializer element is not constant

Sure, what I try is "uncommon" (to the best), but I think that
'"hello"[2]' is a constant value which could be examined. For the
curious, gcc accepts this construct for the second assignment...

The behaviour is the same with gcc-2.95 and gcc-3.0.

MfG, JBG

-- 
   Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481
   "Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur
    fuer einen Freien Staat voll Freier Bürger" | im Internet!
   Shell Script APT-Proxy: http://lug-owl.de/~jbglaw/software/ap2/

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: To const or not to const...
  2003-02-20 14:27 To const or not to const Jan-Benedict Glaw
@ 2003-02-20 16:21 ` Christian Ehrhardt
  2003-02-20 16:24   ` Jan-Benedict Glaw
  0 siblings, 1 reply; 6+ messages in thread
From: Christian Ehrhardt @ 2003-02-20 16:21 UTC (permalink / raw)
  To: Jan-Benedict Glaw; +Cc: gcc

On Thu, Feb 20, 2003 at 03:02:11PM +0100, Jan-Benedict Glaw wrote:
> int main() {
> 	int b = "again_hello"[5]; /* #2 */
> 	return 0;
> }
> 
> 
> Assignment #2 is okay from GCC's eyes, but #1 isn't:

This is because in the case of #2 the initializer need not be constant
because the initialization takes place inside a function.

   regards  Christian

-- 
THAT'S ALL FOLKS!

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

* Re: To const or not to const...
  2003-02-20 16:21 ` Christian Ehrhardt
@ 2003-02-20 16:24   ` Jan-Benedict Glaw
  2003-02-20 17:57     ` Nathan Sidwell
  0 siblings, 1 reply; 6+ messages in thread
From: Jan-Benedict Glaw @ 2003-02-20 16:24 UTC (permalink / raw)
  To: gcc

[-- Attachment #1: Type: text/plain, Size: 1060 bytes --]

On Thu, 2003-02-20 15:27:05 +0100, Christian Ehrhardt <ehrhardt@mathematik.uni-ulm.de>
wrote in message <20030220142705.22460.qmail@thales.mathematik.uni-ulm.de>:
> On Thu, Feb 20, 2003 at 03:02:11PM +0100, Jan-Benedict Glaw wrote:
> > int main() {
> > 	int b = "again_hello"[5]; /* #2 */
> > 	return 0;
> > }
> > 
> > 
> > Assignment #2 is okay from GCC's eyes, but #1 isn't:
> 
> This is because in the case of #2 the initializer need not be constant
> because the initialization takes place inside a function.

"Hello"[2] (which is 'l') is truly constant, in my eyes. This could fall
under C99 6.6. OTOH, as also mentioned on #gcc, this may be some
undefined thing wrt. C99 and it may be in conflict with 6.6.9.
However, I'd love to see this implemented:-)

MfG, JBG

-- 
   Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481
   "Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur
    fuer einen Freien Staat voll Freier Bürger" | im Internet!
   Shell Script APT-Proxy: http://lug-owl.de/~jbglaw/software/ap2/

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: To const or not to const...
  2003-02-20 16:24   ` Jan-Benedict Glaw
@ 2003-02-20 17:57     ` Nathan Sidwell
  2003-02-20 18:27       ` Jan-Benedict Glaw
  0 siblings, 1 reply; 6+ messages in thread
From: Nathan Sidwell @ 2003-02-20 17:57 UTC (permalink / raw)
  To: Jan-Benedict Glaw; +Cc: gcc

Jan-Benedict Glaw wrote:

> 
> "Hello"[2] (which is 'l') is truly constant, in my eyes. This could fall
> under C99 6.6. OTOH, as also mentioned on #gcc, this may be some
> undefined thing wrt. C99 and it may be in conflict with 6.6.9.
> However, I'd love to see this implemented:-)
it fails to be an arithmetic constant expression as it involves something
not on the list of allowed things that [6/6]/9 lists.

But, we're allowed to accept other things in an implementation defined
manner (para 10).

nathan

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
          The voices in my head said this was stupid too
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org


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

* Re: To const or not to const...
  2003-02-20 17:57     ` Nathan Sidwell
@ 2003-02-20 18:27       ` Jan-Benedict Glaw
  2003-02-20 20:20         ` Joseph S. Myers
  0 siblings, 1 reply; 6+ messages in thread
From: Jan-Benedict Glaw @ 2003-02-20 18:27 UTC (permalink / raw)
  To: gcc

[-- Attachment #1: Type: text/plain, Size: 1433 bytes --]

On Thu, 2003-02-20 17:27:30 +0000, Nathan Sidwell <nathan@codesourcery.com>
wrote in message <3E551002.9010902@codesourcery.com>:
> Jan-Benedict Glaw wrote:
> 
> >
> >"Hello"[2] (which is 'l') is truly constant, in my eyes. This could fall
> >under C99 6.6. OTOH, as also mentioned on #gcc, this may be some
> >undefined thing wrt. C99 and it may be in conflict with 6.6.9.
> >However, I'd love to see this implemented:-)
> it fails to be an arithmetic constant expression as it involves something
> not on the list of allowed things that [6/6]/9 lists.

I do not think that 6.6/9 is appropriate: What comes off this notation
is some integer type, it's for sure not an "address constant".
Address/pointer calculation is required to calculate that value,
though...

> But, we're allowed to accept other things in an implementation defined
> manner (para 10).

That sounds better:-) May I open a whishlist bug to get this
implemented?

However - I think leaving this to 6.6/10 isn't all that good. I'm
actually thinking about handing this one over to the C99 folks...

Or could this be a case for 6.6/6 - character constants?

MfG, JBG

-- 
   Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481
   "Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur
    fuer einen Freien Staat voll Freier Bürger" | im Internet!
   Shell Script APT-Proxy: http://lug-owl.de/~jbglaw/software/ap2/

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: To const or not to const...
  2003-02-20 18:27       ` Jan-Benedict Glaw
@ 2003-02-20 20:20         ` Joseph S. Myers
  0 siblings, 0 replies; 6+ messages in thread
From: Joseph S. Myers @ 2003-02-20 20:20 UTC (permalink / raw)
  To: Jan-Benedict Glaw; +Cc: gcc

On Thu, 20 Feb 2003, Jan-Benedict Glaw wrote:

> > But, we're allowed to accept other things in an implementation defined
> > manner (para 10).
> 
> That sounds better:-) May I open a whishlist bug to get this
> implemented?

Such a bug will just be closed.  We don't want to add any new forms of
constant expressions (except for limited new syntax to make offsetof
properly constant when the bug that its present macro expansion counts as
constant is fixed, and possibly specific syntax that can be used to make
other things already used in initializers count as constant), we want to
get rid of the existing undocumented extensions to them instead.

-- 
Joseph S. Myers
jsm28@cam.ac.uk

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

end of thread, other threads:[~2003-02-20 20:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-20 14:27 To const or not to const Jan-Benedict Glaw
2003-02-20 16:21 ` Christian Ehrhardt
2003-02-20 16:24   ` Jan-Benedict Glaw
2003-02-20 17:57     ` Nathan Sidwell
2003-02-20 18:27       ` Jan-Benedict Glaw
2003-02-20 20:20         ` Joseph S. Myers

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).