#Simulating c++ virtual methods issue

1 messages · Page 1 of 1 (latest)

lime isle
#

GetClientNetworkable: *const fn (i32) *anyopaque should be
GetClientNetworkable: *const fn (*anyopaque, i32) callconv(.Thiscall) *anyopaque, and the same for the rest of the virtual calls

#

if you don't tell zig the function is thiscall, zig doesn't know it's thiscall

lilac scarab
#

is the this pointer guaranteed to be passed as the first argument, or how's that work?

lime isle
#

yeah, it's always passed as the first argument in ecx

lilac scarab
#

then I'm assuming that's just common to gcc and clang

#

(which is all you need)

lime isle
#

well, c++ is weird

#

I know msvc uses ecx, gcc is probably different

#

the wikipedia page on calling conventions disagrees

#

For the GCC compiler, thiscall is almost identical to cdecl: The caller cleans the stack, and the parameters are passed in right-to-left order. The difference is the addition of the this pointer, which is pushed onto the stack last, as if it were the first parameter in the function prototype.

#

always best to check what the code does and go from there