Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
March 30, 2006 DMD message of the day ... | ||||
---|---|---|---|---|
| ||||
"incompatible types for ((cast(void*)(src)) + (cast(void*)*(p))): 'void*' and 'void*'" :) |
March 30, 2006 Re: DMD message of the day ... | ||||
---|---|---|---|---|
| ||||
Posted in reply to kris | kris wrote:
> "incompatible types for ((cast(void*)(src)) + (cast(void*)*(p))): 'void*' and 'void*'"
>
> :)
Not really a bug, though the error message might be 'cannot add two pointers' or something alike :)
Tomasz Stachowiak /+ a.k.a. h3r3tic +/
|
March 31, 2006 Re: DMD message of the day ... | ||||
---|---|---|---|---|
| ||||
Posted in reply to kris | 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*'"
>
> :)
|
March 31, 2006 Re: DMD message of the day ... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Unknown W. Brackets | 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
|
March 31, 2006 Re: DMD message of the day ... | ||||
---|---|---|---|---|
| ||||
Posted in reply to kris | Why are you using a pointer type for ptr? That's just asking for trouble, imho... why not use a ptrdiff_t (which is designed for this very purpose, afaik)? Or do you hate those types for some reason?
-[Unknown]
> 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
|
Copyright © 1999-2021 by the D Language Foundation