Structs may not be nested inside structs, only classes

Is there something that doesn't work right in the latest GZDoom? Post about it here.

Moderator: GZDoom Developers

Forum rules
Please construct and post a simple demo whenever possible for all bug reports. Please provide links to everything.

If you can include a wad demonstrating the problem, please do so. Bug reports that include fully-constructed demos have a much better chance of being investigated in a timely manner than those that don't.

Please make a new topic for every bug. Don't combine multiple bugs into a single topic. Thanks!
argv
Posts: 184
Joined: Tue Aug 30, 2016 4:47 pm

Structs may not be nested inside structs, only classes

Post by argv »

I'm not sure if this is intentional, but I notice that while structs can be nested inside classes, they cannot be nested inside other structs.

Because nesting can be helpful for reducing the chance of namespace collisions, please consider allowing that.
User avatar
Major Cooke
Posts: 8170
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Structs may not be nested inside structs, only classes

Post by Major Cooke »

If that were true, Line structs wouldn't be able to store Vertex structs and so on. But then again, they're native...

Are you trying to store structs of the same type into itself? Try making it 'readonly'. That's how the Sector struct does it with the heightsec variable which is also a Sector struct.

No guarantees it'll work, that's just a theory.
User avatar
phantombeta
Posts: 2084
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: Structs may not be nested inside structs, only classes

Post by phantombeta »

No. He's talking about defining structs inside structs.
I'm pretty sure this is intentional. There's nothing in the ZScript syntax to allow structs nested in structs.
User avatar
Major Cooke
Posts: 8170
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Structs may not be nested inside structs, only classes

Post by Major Cooke »

Code: Select all

Class aa
{
	Struct bb
	{
		int volt;
	};
}
Oooh, I see now. Huh. Didn't even know that was doable. TIL!
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Structs may not be nested inside structs, only classes

Post by Graf Zahl »

This is certainly an oversight. The compiler backend can definitely handle such constructs, but it seems the grammar is incomplete.
Post Reply

Return to “Bugs [GZDoom]”