Topic: 9.4.2 static data members -- definition required?


Author: "Stephen Howe" <SPAMGUARDstephen.howe@dial.pipex.co.uk>
Date: 2000/09/25
Raw View
Ron Natalie <ron@sensor.com> wrote in message
news:39CA7C29.5B71A560@sensor.com...
>
>
> "Trevor L. Jackson, III" wrote:
>
> > Ignoring the undefined behavior caused by unsafe casting, should this
> > program fail (to compile or link) due to the lack of a definition for
> > Data::undef?
> >
> Yes.  If you declare a static member, you must provide it's definition
> (9.4.2) of the standard.  Even if you do not create any objects of the
> enclosing class you must provide it (although the compiler is not
obligated
> to give an error).

Hrrrmmm, I have read the sections of the standard carefully and I don't see
it is a fundamental requirement that unreferenced static data/functions of a
class have to be defined. I wish it was clearer. Have I missed something?

Section 9.4.2, point 3 seems to imply that data members must exist. Nothing
on static functions.

--
Stephen Howe


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Ron Natalie <ron@sensor.com>
Date: 2000/09/25
Raw View

Stephen Howe wrote:

>
> Section 9.4.2, point 3 seems to imply that data members must exist. Nothing
> on static functions.

I thought we were talking about data members.  I agree with you.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Ron Natalie <ron@sensor.com>
Date: 2000/09/22
Raw View

"Trevor L. Jackson, III" wrote:

> Ignoring the undefined behavior caused by unsafe casting, should this
> program fail (to compile or link) due to the lack of a definition for
> Data::undef?
>
Yes.  If you declare a static member, you must provide it's definition
(9.4.2) of the standard.  Even if you do not create any objects of the
enclosing class you must provide it (although the compiler is not obligated
to give an error).

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: jim.hyslop@leitch.com (Jim Hyslop)
Date: 2000/09/23
Raw View
On Fri, 22 Sep 2000 07:04:16 GMT, Ron Natalie (ron@sensor.com) wrote in
comp.std.c++...
>
> "Trevor L. Jackson, III" wrote:
>
> > Ignoring the undefined behavior caused by unsafe casting, should this
> > program fail (to compile or link) due to the lack of a definition for
> > Data::undef?
> >
> Yes.  If you declare a static member, you must provide it's definition
> (9.4.2) of the standard.  Even if you do not create any objects of the
> enclosing class you must provide it (although the compiler is not obligated
> to give an error).
Strange, my reading of 9.4.2 comes up with the opposite answer - only
static members that are actually _used_ must be defined. I did not find
anything that explicitly required unused members to be defined, but
paragraph 5 states "There shall be exactly one definition of a static
data member that is used in a program...."

Paragraph 2 doesn't apply, IMO, because it specifies _where_ the
definition must occur, if it occurs at all.

--
Jim

This message was posted using plain text only.  Any hyperlinks you may
see were added other parties without my permission.
I do not endorse any products or services that may be hyperlinked to
this message.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "Trevor L. Jackson, III" <fullmoon@aspi.net>
Date: 2000/09/21
Raw View
Are unreferenced static data members required to exist (be defined)?

Consider:

    struct Data {
        int method() const { return instance; }
        int instance;
        static int const undef;
    };

    main()
    {
        char const memory[ sizeof( Data ) ] = "";
        Data const & ptr = * reinterpret_cast< Data const * >( memory );

        int I = ptr.method();
    }

Ignoring the undefined behavior caused by unsafe casting, should this
program fail (to compile or link) due to the lack of a definition for
Data::undef?


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Jim Hyslop <jim.hyslop@leitch.com>
Date: 2000/09/21
Raw View
In article <39CA635B.261D57A8@aspi.net>,
  "Trevor L. Jackson, III" <fullmoon@aspi.net> wrote:
> Are unreferenced static data members required to exist (be defined)?
[snip]
> Ignoring the undefined behavior caused by unsafe casting, should this
> program fail (to compile or link) due to the lack of a definition for
> Data::undef?
No, to both questions.

9.4.2/5: "There shall be exactly one definition of a static member that
is used in a program; no diagnostic is required...." There are no
requirements placed on static members that are not used.

--
Jim
This message was posted using plain text only.  Any hyperlinks you may
see were added by other parties without my permission.
I do not endorse any products or services that may be hyperlinked to
this message.


Sent via Deja.com http://www.deja.com/
Before you buy.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]