Thread: calling convention stdcalll and cdecl call

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    calling convention stdcalll and cdecl call

    Hello everyone,


    Both stdcall and cdecl calling convention could support variable input parameters? Is that correct?

    (I think stdcall is using RET N and cdecl is using ESP - N, so both are capable to handle variable number of input parameter, like printf?)

    BTW: I have this question because I have something in mind that only one of them supports variable number of parameters, but after reading assembly language code, I think both of them are able to support this feature?


    thanks in advance,
    George

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    No, stdcall can not support variable parameters, since the called function cleans up the stack. To do that, you need to know how much is passed on the stack when building the function, which, as you can probably figure out, printf() doesn't know when you compile printf(). You need to use cdecl for this purpose, so that the stack cleanup is done in the calling code.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed