Topic: useless declarations
Author: pkt@lpi.liant.com (Scott Turner)
Date: Wed, 10 Mar 1993 16:28:03 GMT Raw View
In article <1niq8fINNa45@darkstar.UCSC.EDU>, daniel@cse.ucsc.edu (Daniel R. Edelson) writes:
> >> struct outer {
> >> struct {
> >> static int y;
> >> };
> >> };
>
> >This example is not legal because it's impossible to satisfy the
> >requirement of defining the static member y.
>
> Ok. However, syntactically this is legal (enough)
> for this translation unit to compile to an object module?
Yes.
The natural time to detect the failure to define a static member of an
externally linked class is during linking. In this case the impossibility
of defining the static member could be reported as an error during compilation
of this translation unit. No supplementary translation unit can be written
which would define y, and thereby rescue this current translation unit.
--
Prescott K. Turner, Jr.
Liant Software Corp. (developers of LPI languages)
959 Concord St., Framingham, MA 01701 USA (508) 872-8700
UUCP: uunet!lpi!pkt Internet: pkt@lpi.liant.com
Author: pcwu@csie.nctu.edu.tw ()
Date: Wed, 10 Mar 1993 02:49:52 GMT Raw View
Daniel R. Edelson (daniel@cse.ucsc.edu) wrote:
: Does the draft standard discuss useless nested classes?
: I.e., classes that don't declare anything, neither a tag
: nor an object.
:
As stated in ARM p.165:
" A major use of the unnamed class syntax is the C construct
typedef struct { /* ... */ } mystruct;
That is equivalent to the C++ construct
struct mystruct { /* ... */ };
"
So for the example 2,
: struct outer {
: struct {
: static int y;
: };
: };
it can be modified to:
struct outer {
typedef struct {
static int y;
} useful;
};
int outer::useful::y =0;
Nameless struct is legal in C++ for compatibility to C. A compiler can
give some warning for nameless struct that defines an inaccessible static
member or that does not be used to declare objects. It should not be treated
as severe error. It may be used as placeholder during program development.
Regards,
----------
Pei-Chi Wu
Institute of C.S.I.E.
Nat'l Chiao-Tung Univ.
Hsinchu, Taiwan 30050
Author: daniel@cse.ucsc.edu (Daniel R. Edelson)
Date: 8 Mar 93 19:12:08 GMT Raw View
Does the draft standard discuss useless nested classes?
I.e., classes that don't declare anything, neither a tag
nor an object.
Example:
struct outer {
struct {
int x;
};
};
Or even worse:
struct outer {
struct {
static int y;
};
};
Is this legal?
Thanks.
Daniel Edelson
daniel@cse.ucsc.edu
Author: pkt@lpi.liant.com (Scott Turner)
Date: Tue, 9 Mar 1993 13:54:45 GMT Raw View
In article <1ng5q8INNeu0@darkstar.UCSC.EDU>, daniel@cse.ucsc.edu (Daniel R. Edelson) writes:
> Does the draft standard discuss useless nested classes?
> I.e., classes that don't declare anything, neither a tag
> nor an object.
No. The closest it comes to that is to retain the words of the ARM
"The member-declarator-list can be omitted only after a class-specifier, an
enum-specifier, or a decl-specifier-seq of the form friend
elaborated-type-specifier". (The names of the grammar symbols have been
changed for editorial reasons.)
> struct outer {
> struct {
> static int y;
> };
> };
This example is not legal because it's impossible to satisfy the
requirement of defining the static member y.
--
Prescott K. Turner, Jr.
Liant Software Corp. (developers of LPI languages)
959 Concord St., Framingham, MA 01701 USA (508) 872-8700
UUCP: uunet!lpi!pkt Internet: pkt@lpi.liant.com
Author: daniel@cse.ucsc.edu (Daniel R. Edelson)
Date: 9 Mar 1993 19:13:19 GMT Raw View
In article <1993Mar9.135445.23786@lpi.liant.com> pkt@lpi.liant.com (Scott Turner) writes:
>> struct outer {
>> struct {
>> static int y;
>> };
>> };
>This example is not legal because it's impossible to satisfy the
>requirement of defining the static member y.
Ok. However, syntactically this is legal (enough)
for this translation unit to compile to an object module?
Since the static member could conceivably be defined
in another translation unit, the error might not be
detected here?