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

  • SEARCH
  • Home
  • 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 8606131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:01:19+00:00 2026-06-12T03:01:19+00:00

So I am doing some work in C where I have implementation of the

  • 0

So I am doing some work in C where I have implementation of the same function in both assembly and C and I want to compare the performance of C vs assembly implementation. Now for that I would want to be able to compile and call the function conditionally i.e I would want to create a function which would act as an interface between the caller and the right function that I want to call. somehow I am not sure how to do that.
I was thinking somewhere along the line of following:

//header file containing the C definition and the assembly definition

void getstate(state* m, int* values);   
extern void kalmanstate(state* m, int* values);

Then the caller can include the above header file and pass either &getstate or &kalmanstate.

void callTheRightFunction(state* m, int* values, void *fnptr(state*,int*))
{
  *fnptr(m,values);
}

However the problem with this is that both getstate and kalmanstate will be compiled which kind of defeats the purpose of my simulation. It does not sound to me the best implementation of the wrapper I want to have. I know conditional execution exists in C but how would I use it to get the right function compile? I mean if I do something like this in the header file:

#ifdef __C__FUNC
void getstate(state* m, int *values);
#endif
#ifdef __kalman
void kalmanstate(state *m, int *values)
#endif

Then in the caller:
include “headerfile.h” //include the above header file
//caller defining _C_FUNC
define __C_FUNC
callTheRightFunction(m,p,&getstate);
But since I include the header file at the beginning when none of them are defined it would probably not include any of them at all and thus will generate runtime errro.
Any suggestions towards right direction would be appreciated. Thanks in advance guys!

  • 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-06-12T03:01:20+00:00Added an answer on June 12, 2026 at 3:01 am

    Based on your addition to the original question, you were wondering if none of the functions would be compiled. Then you’ll have to define __C__FUNC or __kalman before you include the header file:

    #define __C__FUNC
    #include "header.h"
    

    But to avoid this problem when you don’t define anything, an approach would be for you to use just one definition, like this, on the SOURCE file:

    #ifdef __GSTATE_USE_C_FUNCTION
    void getstate(state* m, int *values)
    {
        // C version
    }
    #else
    void getstate(state *m, int *values)
    {
        // Assembly version
    }
    #endif
    

    And on the header file:

    void getstate(state *m, int *values);
    

    (Note the same function name, so you don’t need to modify the code when you’re calling the function)

    But this would only work if you’re including the header on the source file where getstate is being implemented too. (*1)

    Then if you forgot to define __GSTATE_USE_C_FUNCTION before your header inclusion, the second function would be used, because it triggered the #else.

    Now, you’d use it like this on a header file that BOTH source files include (that is, the file that implements the function, and the file that uses it):

    // Comment the line below if you want the other version
    #define __GSTATE_USE_C_FUNCTION
    

    Of course you’d have to include this header before including the header which contains the prototype declaration.

    And on the source file:

    // Somewhere else on the code where you use the function
    getstate(m, values);
    

    So you’d only have to change the #define line on the global header.

    In addition, if your compiler has an option to do preprocessor defining in the command line for it, then you’d not even need to define __GSTATE_USE_C_FUNCTION before the #include, you’d just use as a command line option, something like this (for example in bcc32):

    bcc32 /D"__GSTATE_USE_C_FUNCTION" hello.c
    

    This would avoid the problem (*1), and you’d not have to make a global header file that both source files have to include.

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

Sidebar

Related Questions

I am doing some work with Web.Routing, using it to have friendly urls and
I'm doing some JAVA coding at home and at work. At home i have
I have no idea why this doesn't work, but doing some validation functions and
I'm doing some work with stats, and want to refactor the following method :
I have a class, and I am doing some nifty things with reflection. Now
I'm doing some R&D work, and as such am exploring design patterns. I have
I have a database of tables that I needed to do some comparison work
I am currently doing some work on a research database where they have decided
I'm doing some work with grades and the desire2learn Valence API. In the context
I am doing some work to track down a perceived bug in a git

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.