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 8350931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:28:21+00:00 2026-06-09T08:28:21+00:00

GCC has a nice feature about instrumentation which let you call a routine every

  • 0

GCC has a nice feature about instrumentation which let you call a routine every time a function is called, or every time a function returns.

Now, I want to create my own system to make it portable to other compilers, and also to allow to instrumentalize the functions I want (which can vary in number of parameters), so I was thinking in two macro for both situations. I am thinking in making some kind of profile that it is activated only with a define clause.

#define FUNCT(t,function_name,...)   \
    (t) function_name(...) { \
        (void) *func_pointer = &(function_name); \
        start_data(func_pointer, myclock());

#define RETURN(x) {stop_data(func_pointer, myclock()); return (x);}

FUNCT(BOOL, LMP, const int prof, const int nmo))
    if (nmo <= 5 ||
        prof > (prof_l / 3)) {
        .... do long operations....
        RETURN(FALSE);
    }
    ... do more....
    RETURN(TRUE);
}

but I can’t get it to work. Can someone help me with this? or is this a difficult task to accomplish?

Other alternative that comes to my mind is let the function declare without a macro, and if it is anyway to know the function pointer without knowing its name, something like in VB when you call a Form with Me, with it is a generic alias. is it possible?

  • 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-09T08:28:23+00:00Added an answer on June 9, 2026 at 8:28 am

    Use gcc -E to debug your macros. Using the code you posted:

    $ gcc -E t.c
    # ... skip stuff ....
    
    (BOOL) LMP(...) { (void) *func_pointer = &(LMP);
                      start_data(func_pointer, myclock());)
        if (nmo <= 5 ||
            prof > (prof_l / 3)) {
            .... do long operations....
            {stop_data(func_pointer, myclock()); return (FALSE);};
        }
        ... do more....
        {stop_data(func_pointer, myclock()); return (TRUE);};
    }
    

    (I added some whitespace to make it readable.)

    You can see two problems immediately: function arguments didn’t get expanded as you thought they would, and there’s an extra ) from somewhere.

    To get the expanded variadic arguments, use __VA_ARGS__, not .... The stray ) is at the call site.

    So:

    #define FUNCT(t,function_name,...)   \
        (t) function_name(__VA_ARGS__) { \
            (void) *func_pointer = &(function_name); \
            start_data(func_pointer, myclock());
    
    #define RETURN(x) {stop_data(func_pointer, myclock()); return (x);}
    
    FUNCT(BOOL, LMP, const int prof, const int nmo)
        if (nmo <= 5 ||
            prof > (prof_l / 3)) {
            .... do long operations....
            RETURN(FALSE);
        }
        ... do more....
        RETURN(TRUE);
    }
    

    As to whether this is worth trying (variadic macros came with C99, not all compilers implement that standard, and support might vary from compiler to compiler), I’m not certain. You are probably better off using each compiler’s native profiling tools – you’ll get better results with hopefully less overhead.

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

Sidebar

Related Questions

gcc 4.4.2 c89 I have a function that has to run (config_relays). It make
I have a c-library which I use in gcc. The library has the extension
GCC seem to think that I am trying to make a function call in
I need to deploy to a Red Hat 4.1.2 box (which has gcc 4.1.2).
gcc has a very nice extension in C that allows you to keep data
How would I go about checking whether gcc has succeeded in compiling a program,
So I've been getting into the new C++ using GCC 4.6 which now has
I'm wondering if there is a nice way to avoid gcc to scream about
GCC has a statment expression feature that allows macro to be defined as: #define
I have installed gcc-3.3/g++-3.3 on ubuntu 11.04 which already has gcc/g++-4.4. So in my

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.