DMD message of the day ...

kris foo at bar.com
Thu Mar 30 23:19:18 PST 2006


Unknown W. Brackets wrote:
> Shouldn't you make them ubytes or something first?
> 
> Also, forgive my ignorance, but for what good reason would you add two 
> pointers?  Subtracting is great and wonderful... adding a pointer and an 
> int is amazing...  but adding pointers?
> 
> -[Unknown]
> 
> 
>> "incompatible types for ((cast(void*)(src)) + (cast(void*)*(p))): 
>> 'void*' and 'void*'"
>>
>> :)

Yeah ... it is a bit odd :)

This came up when serializing & deserializing arrays. I ended up 
modifying each array pointer|length pair to be an offset|length pair 
instead, and then writing that pair as though it were an ordinary field 
(like a long int).

When deserializing, the offset|length pair gets converted back to a 
pointer|length pair by adding a base-address to the offset. Hence, we 
end up with what /looks/ like the addition of two pointers.

The decoding looked something like this:

void* base_address;
void[]* p = address_of_encoded_array;
*p = (base_address + (*p).ptr)[0 .. (*p).length];

where (*p).ptr is actually the encoded offset, rather than a pointer. 
That's where DMD tossed the amusing "void* is incompatible with void*" 
error. This was fixed by removing the .ptr syntax, causing DMD to 
extract the offset via implicit type-casting instead (matching the void* 
on the LHS).

The approach is a bit grubby, but that's ok.

- Kris



More information about the Digitalmars-d-bugs mailing list