Re: Labels in struct

2015-01-31 Thread tcak via Digitalmars-d-learn
On Saturday, 31 January 2015 at 16:04:36 UTC, tcak wrote: I do not have a big example in the end to show, but is there any way to put labels into struct definitions? struct CommunicationMessage{ char[2] signature; mainData: int info1; int info2; extraData: ushort checksum

Re: Labels in struct

2015-01-31 Thread Adam D. Ruppe via Digitalmars-d-learn
You could use a UDA like that, though getting the offset will be a bit tricky. The idea is to use some uda type, even plain string is good enough, then use the __traits to find the first appearance of that UDA in the object and return that offset. Keep in mind that the @uda: syntax applies

Re: Labels in struct

2015-01-31 Thread Adam D. Ruppe via Digitalmars-d-learn
Oh this hack also won't work with a label at the very end. You could use sizeof for that though (however that would include padding bytes. Perhaps last member's offsetof plus last member's sizeof is a bit more accurate.)

Labels in struct

2015-01-31 Thread tcak via Digitalmars-d-learn
I do not have a big example in the end to show, but is there any way to put labels into struct definitions? struct CommunicationMessage{ char[2] signature; mainData: int info1; int info2; extraData: ushort checksum; content: } Example I defined something like above. I am

Re: Labels in struct

2015-01-31 Thread Artur Skawina via Digitalmars-d-learn
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

Re: Labels in struct

2015-01-31 Thread zeljkog via Digitalmars-d-learn
On 31.01.15 17:04, tcak wrote: I do not have a big example in the end to show, but is there any way to put labels into struct definitions? struct CommunicationMessage{ char[2] signature; mainData: int info1; int info2; extraData: ushort checksum; content: } Members