How to handle nested structs when converting C headers?

Gary Willoughby dev at nomad.so
Wed Dec 11 15:35:02 PST 2013


On Wednesday, 11 December 2013 at 23:27:57 UTC, Gary Willoughby 
wrote:
> On Wednesday, 11 December 2013 at 23:12:39 UTC, bearophile 
> wrote:
>> Adam D. Ruppe:
>>
>>> Nested structs and unions like in your example are supported 
>>> in D too, same syntax, same effect.
>>
>> But don't forget to add to use "static struct" instad of 
>> "struct".
>>
>> Bye,
>> bearophile
>
> Have you got an example because i always get:
>
> tcl.d(713): Error: no identifier for declarator twoPtrValue
> tcl.d(718): Error: no identifier for declarator ptrAndLongRep
> tcl.d(719): Error: no identifier for declarator internalRep

Like this perhaps:

struct Tcl_Obj
{
     int refCount;
     char* bytes;
     int length;
     Tcl_ObjType* typePtr;

     static union internalRep
	{
		c_long longValue;
		double doubleValue;
		void* otherValuePtr;
		Tcl_WideInt wideValue;

		static struct twoPtrValue
		{
			void* ptr1;
			void* ptr2;
		}

		static struct ptrAndLongRep
		{
			void* ptr;
			c_ulong value;
		}
     }
}


More information about the Digitalmars-d-learn mailing list