public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: corey taylor <corey.taylor@gmail.com>
To: John Ratliff <webmaster@technoplaza.net>
Cc: MSX to GCC <gcc-help@gcc.gnu.org>
Subject: Re: C++ static integer class constants...
Date: Mon, 17 Oct 2005 18:07:00 -0000	[thread overview]
Message-ID: <2e393d080510171107l678b0570u8f9eb3876deac2a3@mail.gmail.com> (raw)
In-Reply-To: <4353e481.0829b6d6.64bd.18a4SMTPIN_ADDED@mx.gmail.com>

The 2003 specification basically agrees:

If a static data member is of const integral or const enumeration
type, its declaration in the class
definition can specify a constant-initializer which shall be an
integral constant expression (5.19). In that
case, the member can appear in integral constant expressions. The
member shall still be defined in a namespace
scope if it is used in the program and the namespace scope definition
shall not contain an initializer.

The explanation of "use" is obvious in that context as meaning used
outside of a constant integral expression.

corey

On 10/17/05, John Ratliff <webmaster@technoplaza.net> wrote:
> Well, this just gets more complicated everyday.
>
> The 9.4.2, par 4 section of the standard 1998 in any case (I don't have
> access to the 2003 version) says you must declare the variable. But then it
> goes on to say that if you do, you can't use the initializer. So g++ 3.3 is
> correct, and 3.4 is just a better optimizer.
>
> So, you can use named static constants as long as they only appear in the
> class-def, and I am supposed to define them if they are "used" in the
> program, though the definition of "used" is somewhat debatable.
>
> However, this is not what was intended, and is proposed for change.
>
> The DR on this:
> http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#48
>
> More on this:
> http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#454
>
> I already know bout the enum hack, but this is supposed to supplant and
> remove it.
>
> --John Ratliff
>
>
> > -----Original Message-----
> > From: John Love-Jensen [mailto:eljay@adobe.com]
> > Sent: Monday, October 17, 2005 7:03 AM
> > To: John Ratliff; MSX to GCC
> > Subject: Re: C++ static integer class constants...
> >
> > Hi John,
> >
> > To get the behavior you want without having to define the static class
> > constant in some translation unit, use an anonymous enum:
> >
> > class foo {
> > public:
> >   enum { X = 5, Y = 10, Z = 15 };
> > };
> >
> > >Is this correct behavior?
> >
> > I believe your example demonstrates the correct behavior.
> >
> > In that *IF* you specify the value of a static const int in the
> > declaration, that both you *MUST* define the static const int in
> > one-and-only-one translation unit, and you *MUST NOT* specify the
> > initialization value in that definition.
> >
> > HTH,
> > --Eljay
> >
>
>
>
>

  parent reply	other threads:[~2005-10-17 18:07 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200510160743.j9G7hVoa010304@inbound-smtp-1.corp.adobe.com>
2005-10-17 12:05 ` John Love-Jensen
2005-10-17 17:50   ` John Ratliff
2005-10-17 17:50   ` John Ratliff
     [not found]   ` <4353e481.0829b6d6.64bd.18a4SMTPIN_ADDED@mx.gmail.com>
2005-10-17 18:07     ` corey taylor [this message]
2005-10-17 20:04       ` John Ratliff
2005-10-17 20:04       ` John Ratliff
     [not found] <0IOJ0024ULK8BF@emroute1.cind.ornl.gov>
2005-10-18 12:26 ` Ernest L. Williams Jr.
     [not found] <87oe5pb5dp.fsf@totally-fudged-out-message-id>
2005-10-17 19:17 ` Florian Weimer
2005-10-18  6:19   ` John Ratliff
2005-10-18  6:19   ` John Ratliff
     [not found] <20051016195314.7EFB824AEF5@lax-gw02.mroute.net>
2005-10-17  9:09 ` Nathan Sidwell
2005-10-17 19:21   ` Florian Weimer
     [not found] <20051016200125.C061F13137C@arvo.suso.org>
2005-10-16 21:36 ` John Ratliff
2005-10-16 21:36 ` John Ratliff
2005-10-16 15:26 Ryan Mansfield
2005-10-16 16:16 ` John Ratliff
2005-10-16 16:16 ` John Ratliff
2005-10-16 16:42 ` John Ratliff
2005-10-16 16:42 ` John Ratliff
     [not found] ` <43528310.03f34613.6a05.0e40SMTPIN_ADDED@mx.gmail.com>
2005-10-16 17:43   ` Alex J. Dam
     [not found]     ` <4352a3b2.42389977.3b5e.60fdSMTPIN_ADDED@mx.gmail.com>
2005-10-16 19:29       ` Alex J. Dam
2005-10-16 19:53         ` John Ratliff
2005-10-16 19:53         ` John Ratliff
2005-10-16 19:45     ` John Ratliff
2005-10-16 19:45     ` John Ratliff
     [not found] <435202e6.3d759d8f.4550.fffff1e6SMTPIN_ADDED@mx.gmail.com>
2005-10-16 14:50 ` Alex J. Dam
2005-10-17 19:13   ` Florian Weimer
  -- strict thread matches above, loose matches on Subject: below --
2005-10-16  7:35 John Ratliff
2005-10-16  7:35 John Ratliff

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2e393d080510171107l678b0570u8f9eb3876deac2a3@mail.gmail.com \
    --to=corey.taylor@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=webmaster@technoplaza.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).