0

Actually my real question is that I've noticed some people explicitly specify __fastcall or __cdecl in x64 code but I don't understand what the point is? Are they not the same thing in x64 and totally unnecessary since the default is __fastcall anyway? The only scenario I can think of is that you want the code to behave the same in x86. So if I'm certain I'll always be working with x64, there's no need to explicitly specify them?

uNiverselEgacy
  • 337
  • 3
  • 14
  • @RetiredNinja I'm aware of that post and have read it beforehand but I still don't understand why you write them explicitly. – uNiverselEgacy Jan 22 '17 at 19:15
  • 1
    Because the code you're looking at isn't x64 code, but C++ code (specifically Microsoft's variant of C++). – Ross Ridge Jan 22 '17 at 19:19
  • @RossRidge I'm certain that it is indeed x64 code because the target says x64 and it is a plugin for an x64 only game. Are you implying that they are indeed unnecessary or even "wrong" in some sense in x64 code? – uNiverselEgacy Jan 22 '17 at 19:29
  • You might still want to use `__cdecl` on x64 if you're building with `/Gv`. The documentation actually says exactly that: *On ARM and x64 processors, `__cdecl` is accepted but typically ignored by the compiler. By convention on ARM and x64, arguments are passed in registers when possible, and subsequent arguments are passed on the stack. In x64 code, use `__cdecl` to override the **/Gv** compiler option and use the default x64 calling convention.* ([__cdecl](https://msdn.microsoft.com/en-us/library/zkwh89ks.aspx)) – conio Jan 22 '17 at 19:31
  • Maybe the authors of your mysterious plugin used code from another source and didn't bother to remove the calling convention modifiers. Maybe they wanted to write code that **could** work on x86-32 (so they declared callback function as `__stdcall`), if it ever became needed. Maybe something else. It's not strictly wrong, just unnecessary and ignored. It's like writing `signed int` instead of `int`. – conio Jan 22 '17 at 19:36
  • @MegaStupidMonkeys That just means it's C++ code targeted for x64. Only x64 assembly code can be accurately called "x64 code". I can't read mind of whoever wrote the code you're looking at but as conio explained there's a number of possible reasons why they did that despite it having no effect when compiled for an x64 target. – Ross Ridge Jan 22 '17 at 19:48

0 Answers0