[Vm-dev] Better type than void* for primitiveFunctionPointer?

Igor Stasenko siguctua at gmail.com
Wed Apr 16 06:16:01 UTC 2008


In Hydra, i added declaration of primitive function type:

typedef sqInt (*PrimitiveFn)(struct Interpreter *) __attribute__((cdecl));

So, later in code its using this type:

	PrimitiveFn primitiveFunctionPointer;
	PrimitiveFn externalPrimitiveTable[4097];
sqInt callExternalPrimitive(struct Interpreter *intr, PrimitiveFn functionID);

and so on..

Note about cdecl attribute. It was placed explicitly to make sure that
primitive functions always get called using cdecl calling convention.
We need this to not make difference between calling 'legacy'
primitives and primitives which expect additional argument
(interpreter instance).
A cdecl calling convention helping us to call functions which not
expecting any arguments as function which expects one. In this case
argument just ignored, and what is important, since with cdecl calling
convention only a caller responsive from cleaning a stack after call,
there is no stack corruption.

2008/4/16 Andreas Raab <andreas.raab at gmx.de>:
>
>  Ian Piumarta wrote:
>
> > The comment was a note from me to me.  Go ahead and remove it; it's
> unlikely I'll ever get around to fixing it.  Can't say anything about any
> other comments you don't like and choose to delete unilaterally.
> >
>
>  Fortunately it's a rare occurrence to find such comments in the code.
>
>  Cheers,
>   - Andreas
>



-- 
Best regards,
Igor Stasenko AKA sig.


More information about the Vm-dev mailing list