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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:01:22+00:00 2026-05-22T21:01:22+00:00

Given many inline functions with identical signatures. All functions are small and performance critical.

  • 0

Given many inline functions with identical signatures. All functions are small and performance critical.

int inline f1(int);
int inline f2(int);
...
int inline f5(int);

I need to write high level functions to automate certain tasks – one high level function per each inline function. n-th high level function uses only n-th low level function, otherwise all high level functions are identical.

int F_n(int x) {
    int y;
    // use n-th low level function to compute y from x
    // for example
    y = x*f_n(x);

    return y;
}

I could use function pointers for call back, but I think it will prevent inclining and the performance will suffer. Or I could just copy&paster and manually fix function names.

Is there a way to do it with macros? A macro that can generates high level functions automatically?

#define GEN_FUNC( HIGH_LEVEL_FUNC, LOW_LEVEL_FUNC ) \
???????               \
???????               \

GEN_FUNC(F1, f1); // generate F1
GEN_FUNC(F2, f2); // generate F2
.........
GEN_FUNC(F_N, f_N); // generate F_N

Is it possible?

Thanks.

P.S. I could use function objects, but it should work in C too.

  • 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-22T21:01:22+00:00Added an answer on May 22, 2026 at 9:01 pm

    Why not use templates?

    template <int N>
    int inline f(int);
    
    template <>
    int inline f<1>(int);
    
    template <>
    int inline f<2>(int);
    
    template <>
    int inline f<3>(int);
    
    ...
    
    template <int N>
    int F(int x)
    {
        int y;
        y = x * f<N>(x);
        return y;
    }
    

    Edit: If it should work in C, use a macro like this:

    #define GENERATE_FUNCTION(n) \
        int F_ ## n(int x) {     \
            int y;               \
            y = x*f_ ## n(x);    \
            return y;            \
        }
    

    And using BOOST_PP_REPEAT:

    #define GENERATE_FUNCTION_STEP(z, n, unused) GENERATE_FUNCTION(n)
    
    BOOST_PP_REPEAT(N, GENERATE_FUNCTION_STEP, ~)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a date range, I need to know how many Mondays (or Tuesdays, Wednesdays,
first of all, i am sorry that even if there's many given topic that
It seems that the following is a common method given in many tutorials on
Given that there are many sizes and color depths for different phones (even for
Given that every software project only has so many programmer-hours dedicated to it, how
Given an HTML page that has a complex table-based layout and many tags that
Given 2 file revisions I want to know how many lines were added/modified/deleted. I
Many thanks for the advice you have given me thus far. Using testbenches is
Given a situation in Django 1.0 where you have extra data on a Many-to-Many
Simple task: given that an article has many comments, be able to display in

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.