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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:36:19+00:00 2026-05-18T22:36:19+00:00

I have a series of functions with the same prototype, say int func1(int a,

  • 0

I have a series of functions with the same prototype, say

int func1(int a, int b) {
  // ...
}
int func2(int a, int b) {
  // ...
}
// ...

Now, I want to simplify their definition and declaration. Of course I could use a macro like that:

#define SP_FUNC(name) int name(int a, int b)

But I’d like to keep it in C, so I tried to use the storage specifier typedef for this:

typedef int SpFunc(int a, int b);

This seems to work fine for the declaration:

SpFunc func1; // compiles

but not for the definition:

SpFunc func1 {
  // ...
}

which gives me the following error:

error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token

Is there a way to do this correctly or is it impossible?
To my understanding of C this should work, but it doesn’t. Why?


Note, gcc understands what I am trying to do, because, if I write

SpFunc func1 = { /* ... */ }

it tells me

error: function 'func1' is initialized like a variable

Which means that gcc understands that SpFunc is a function type.

  • 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-18T22:36:19+00:00Added an answer on May 18, 2026 at 10:36 pm

    You cannot define a function using a typedef for a function type. It’s explicitly forbidden – refer to 6.9.1/2 and the associated footnote:

    The identifier declared in a function definition (which is the name of the function) shall
    have a function type, as specified by the declarator portion of the function definition.

    The intent is that the type category in a function definition cannot be inherited from a typedef:

    typedef int F(void); // type F is "function with no parameters
                         // returning int"
    F f, g; // f and g both have type compatible with F
    F f { /* ... */ } // WRONG: syntax/constraint error
    F g() { /* ... */ } // WRONG: declares that g returns a function
    int f(void) { /* ... */ } // RIGHT: f has type compatible with F
    int g() { /* ... */ } // RIGHT: g has type compatible with F
    F *e(void) { /* ... */ } // e returns a pointer to a function
    F *((e))(void) { /* ... */ } // same: parentheses irrelevant
    int (*fp)(void); // fp points to a function that has type F
    F *Fp; //Fp points to a function that has type F
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a series of functions that are all designed to do the same
Say I have two factors and I want to graph them on the same
I have a constructor that has a series of classes and functions within it
I have a series of web sites all hosted on the same server with
I have inherited a piece of code which has a series of functions like
I have a series of spectral data which I want to plot in a
I have a series of divs that I want to clone and show/hide on
I have a series of anonymous jQuery/javascript functions for click events which have to
I have a function that makes a series of calls to sscanf() and then,
I have a series of functional tests against a web application that correctly run,

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.