Labels in struct

Artur Skawina via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 31 09:58:50 PST 2015


On 01/31/15 17:04, tcak via Digitalmars-d-learn wrote:
> 
> struct CommunicationMessage{
[...]
> content:
> }
> 
> 
> Example I defined something like above. I am using it as a base structure, and don't know how long the content of message will be. But I know that it will be at the end. I could use that "content" label to find out about end of struct. But unfortunately, it doesn't seem like it is supported.
> 
> I could say "void* endOfStruct = &struct + sizeof(struct)", but then struct wouldn't be self explanatory with that content label at the end.

The traditional way (ie C-like) would be

   ubyte[0] content; // zero-sized; use casts etc to access data.

as the last member. D supports that too, and just like
many other D features it works for ~80% of cases. IOW
you should be able to get it to work, but you might run
into problems if you need to access/manipulate such types.

artur


More information about the Digitalmars-d-learn mailing list