Topic: structs that define nothing
Author: b91926@fnalng.fnal.gov
Date: 25 Jan 93 17:12:22 -0600 Raw View
Does the c++ standard have anything to say about the legality of a
construct like the following:
...
struct
{
int a;
int b;
};
...
Such an example appeared in a recent issue of "C++ Report". The
problem with this code is that it defines absolutely nothing.
Author: dwr@cci632.cci.com (Donald W. Rouse II)
Date: 27 Jan 93 17:33:19 GMT Raw View
In article <1993Jan25.171222.1@fnalng.fnal.gov> b91926@fnalng.fnal.gov writes:
>Does the c++ standard have anything to say about the legality of a
>construct like the following:
>
>...
>struct
>{
> int a;
> int b;
>};
>
>...
>
>Such an example appeared in a recent issue of "C++ Report". The
>problem with this code is that it defines absolutely nothing.
This example reminds me of a possible extension to C++ (and C)
that could occasionally be useful: anonymous structures,
which are analogous to anonymous unions.
Example:
typedef union
{
unsigned long lw;
struct { unsigned short sw0, sw1; };
struct { unsigned char b0, b1, b2, b3; };
} machword;
machword r1, r2;
Now you can access r1.b2, instead of having to do
something like r1.b.b2, etc.
Note that the only place this would be useful
is inside a union.