Re: `enum x;` - what is it?

2020-08-19 Thread FeepingCreature via Digitalmars-d-learn

On Wednesday, 19 August 2020 at 14:43:22 UTC, Victor Porton wrote:
On Wednesday, 19 August 2020 at 14:06:16 UTC, Victor Porton 
wrote:

This declaration does compile:

enum x;

But what is it? Is it an equivalent of

enum x { }

?

What in the specification allows this looking a nonsense

enum x;

?


Oh, found: "An empty enum body (For example enum E;) signifies 
an opaque enum - the enum members are unknown."


But what this "unknown" does mean? How "unknown" differs from 
"none" in this context?


The specification is unclear. It does not define the meaning of 
unknown. I will submit a bug report.


It means exactly what it says. The compiler doesn't know what 
members are in the enum. So you can't declare a variable of it, 
you can't use it directly.. you can p much only use it in 
pointers.


Re: `enum x;` - what is it?

2020-08-19 Thread Victor Porton via Digitalmars-d-learn

On Wednesday, 19 August 2020 at 14:06:16 UTC, Victor Porton wrote:

This declaration does compile:

enum x;

But what is it? Is it an equivalent of

enum x { }

?

What in the specification allows this looking a nonsense

enum x;

?


Oh, found: "An empty enum body (For example enum E;) signifies an 
opaque enum - the enum members are unknown."


But what this "unknown" does mean? How "unknown" differs from 
"none" in this context?


The specification is unclear. It does not define the meaning of 
unknown. I will submit a bug report.


Re: `enum x;` - what is it?

2020-08-19 Thread Steven Schveighoffer via Digitalmars-d-learn

On 8/19/20 10:06 AM, Victor Porton wrote:

This declaration does compile:

enum x;

But what is it? Is it an equivalent of

enum x { }

?

What in the specification allows this looking a nonsense

enum x;

?


I use it as a symbol for UDAs.

enum required;

struct S
{
   @required int x;
}

which can then easily be found.

What is it? I have no idea. I'm just using the name.

I think it's treated as a forward declaration. Kind of like

void foo();

-Steve


Re: `enum x;` - what is it?

2020-08-19 Thread FeepingCreature via Digitalmars-d-learn

On Wednesday, 19 August 2020 at 14:06:16 UTC, Victor Porton wrote:

This declaration does compile:

enum x;

But what is it? Is it an equivalent of

enum x { }

?

What in the specification allows this looking a nonsense

enum x;

?


It's an enum type whose members we don't know.

So we can't declare "x var;" but we can declare "x* var;".

It's the enum version of "struct SomeExternCStruct;".