Hi Seb,
yes, that's a (little known) quirk of Pd's type-checked arguments: if your method signature contains a mix of float and symbols/gpointers, all the symbols/gpointers arguments are passed *before* all float arguments.
Take the following method, for example:
class_addmethod(foo_class, (t_method)foo_bark, gensym("bark"), A_FLOAT, A_SYMBOL, A_FLOAT, A_SYMBOL, 0);
The C function must then be declared like this:
void foo_bark(t_foo *x, t_symbol *arg2, t_symbol *arg4, t_floatarg arg1, t_floatarg arg3) { // ... }
The numbering in the arguments are supposed to show how the C function arguments related to the Pd method arguments.
---
Originally, this was a clever trick to avoid having a big switch statement in the message dispatcher. Pd only had to check the number of t_int arguments and then just pushed all 6 float arguments, regardless of the actual C function signature. This means that it would typically push more float arguments than the C function accepts. This happened to work because in all the relevant calling conventions the stack is cleaned up by the caller. (For example, this would have *not* worked with Microsoft's __stdcall.) We had to change this recently because some platforms, most notably WASM, are more strict about argument passing. Now we do have a switch statement, see mess_dispatch(), but the argument reordering is still useful for keeping the number of combinations down. If you're curious, check the implementation of pd_typedmess().
---
Personally, I tend to use A_GIMME when I have a method that mixes float and symbols arguments, in particular if the C function arguments would need to be reordered.
I thought it had been working before but maybe I just missed it somehow..
The fun thing is that declaring the function arguments in the wrong order may appear to work on some platforms depending on the calling convention, in particular if all arguments are passed by register.
Is this documented anywhere?
I'm not sure. Probably not :)
Christof
On 17.08.2025 18:37, Sebastian Shader via Pd-dev wrote:
Hello list, Recently I noticed one of my externals was having an error, I think it's due to the typechecked argument list (when not using A_GIMME) always calling methods with the floats at the end. (my external had DEFFLOAT, DEFFLOAT, DEFSYMBOL).
I thought it had been working before but maybe I just missed it somehow.. Is this documented anywhere?
Thanks, -Seb
pd-dev@lists.iem.at - the Pd developers' mailinglist https://lists.iem.at/hyperkitty/list/pd-dev@lists.iem.at/message/VGSB7SB26VM...