Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6371395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:03:45+00:00 2026-05-25T01:03:45+00:00

I have the following code: typedef void * (__stdcall * call_generic)(…); typedef void *

  • 0

I have the following code:

typedef void * (__stdcall * call_generic)(...);
typedef void * (__stdcall * call_push2)(unsigned long,unsigned long);

void * pfunc;
// assume pfunc is a valid pointer to external function

// this is a logically correct way of calling, however this includes:
// add esp, 8
// after the call, and that breaks my stack.
((call_generic)pfunc)(1,1);

// however, if i use this call:
((call_push2)pfunc)(1,1);
// this does not happen and code works properly.

It’s a pain to track all the calls and count args manually (there are lots of such calls ahead), I’d prefer a macro or something for this, but with that bug it’s not possible.

Is there a solution? Is there another way of creating call_generic type to do such things?

I do not really understand why exactly it does that “cleanup” but that breaks my stack badly, causing previously defined variables to be lost.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:03:46+00:00Added an answer on May 25, 2026 at 1:03 am

    ((call_generic)pfunc)(1,1); is only a logically correct way of calling if the function pointed to by pfunc actually has the signature you cast to, void *(...). Your code tells the compiler to make a varargs call, so it makes a varargs call. A varargs call to a function that isn’t a varargs function doesn’t work (in this case, there’s disagreement who has to clean up the stack, and it gets done twice).

    There’s no way to do this for free. You must somehow cast the function pointer to the correct signature before calling it, otherwise the calling code doesn’t know how to pass the parameters in a way that the callee code can use.

    One option is to ensure that all the called functions that pfunc might point to have the same signature, then cast to that type. For example, you could make them all varargs functions, although I don’t particularly recommend it. It would be more type safe to do what you don’t want to – make sure that all the functions that might appear here take two unsigned long, and cast to call_push2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: typedef void VOID; int f(void); int g(VOID); which compiles
I have the following code: template <typename Provider> inline void use() { typedef Provider::Data<int>
I have the following code: #include <stdlib.h> #include <stdio.h> typedef void (*func_t)(void * data);
I have the following code: typedef __int64 BIG_INT; typedef double CUT_TYPE; #define CUT_IT(amount, percent)
I have the following code parts: typedef struct Board* BoardP; typedef struct Board {
I have the following code: template<typename Parent, typename T, void (Parent::*Setter)(T), T (Parent::*Getter)()> struct
I have the following code: /* * Pointer to a function that reads a
I have the following code, which does some iterator arithmetic: template<class Iterator> void Foo(Iterator
gcc 4.4.4 c89 I have the following code in my channel.h file typedef struct
I have the following data structure in C: typedef struct { void* buffer; ...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.