[Issue 1648] New: Casting a function literal to void* swallows the function or segfaults

Jarrett Billingsley kb3ctd2 at yahoo.com
Thu Nov 8 07:14:07 PST 2007


<d-bugmail at puremagic.com> wrote in message 
news:bug-1648-3 at http.d.puremagic.com/issues/...
> http://d.puremagic.com/issues/show_bug.cgi?id=1648
>
>           Summary: Casting a function literal to void* swallows the
>                    function or segfaults
>           Product: D
>           Version: 2.007
>          Platform: PC
>        OS/Version: Linux
>            Status: NEW
>          Severity: normal
>          Priority: P2
>         Component: DMD
>        AssignedTo: bugzilla at digitalmars.com
>        ReportedBy: dhasenan at gmail.com
>
>
> When saving a delegate as a void* and only using one delegate from the 
> same
> function, attempts to execute the delegate by casting to the original type 
> do
> nothing.
>
> When saving multiple delegates from the same function, if any of them are 
> cast
> to void*, a segmentation fault occurs.
>
> Casting is inherently dangerous, I know, but there's no other way to pass 
> a
> delegate while ignoring its type.
>
>
> -- 
>

delegate.sizeof != (void*).sizeof.

It's no real surprise that this doesn't work.  Delegates are not simple 
pointers; they are actually a struct with two members, but you shouldn't 
really be relying on the underlying implementation in any way.

What is it that you're trying to do, anyway?  Delegates are strongly typed 
for a reason -- the compiler can't generate the correct call sequence unless 
it knows the exact type of the delegate.  There's probably a much better way 
of doing what you want. 




More information about the Digitalmars-d-bugs mailing list