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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:50:32+00:00 2026-06-07T19:50:32+00:00

This code causes compilation error error: redefinition of ‘p’ with a different type: void

  • 0

This code causes compilation error ” error: redefinition of ‘p’ with a different type”:

void fun() {
    printf("fun");
}
void (*p)();
p = &fun;

But if modify
void (*p)(); p = &fun; to
void (*p)() = &fun, everything is OK.

What’s the difference between
void (*p)(); p = &fun; and
void (*p)() = &fun?

  • 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-07T19:50:35+00:00Added an answer on June 7, 2026 at 7:50 pm

    The three prior answers do not answer the question and are incorrect when they indicate that “p = &fun;” is an assignment.

    Actually, the compiler is attempting to interpret “p = &fun;” as a declaration, so “p” is a declarator, “&fun” is an initializer, and “p = &fun” forms an init-declarator (in the formal grammar of the C specification).

    Having interpreted this as a declaration, the type that should be in the declaration defaults to int (for legacy reasons), so the compiler essentially sees this as “int p = &fun;”, which is a definition of p. Because p was previously defined as a pointer to a function, the compiler complains that you are redefining p with a different type.

    For the language grammarians: I cannot make out how this could be a declaration in the formal grammar. A translation-unit would expand to an external-declaration, an external-declaration would expand to a declaration, and a declaration would expand to “declaration-specifiers init-declarator-list[opt];” (per 6.7 in the C standard). The declaration-specifiers appear to require at least one of the keywords involved in storage-class-specifier, type-specifier, type-qualifier, or function-specifier. No such keyword appears in the source, so this cannot be a declaration. I suspect the compiler is parsing with some grammar from before the 1999 standard, so this is legacy behavior. Nonetheless, the error message makes it clear the compiler has seen two definitions, not a definition followed by an assignment.

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

Sidebar

Related Questions

Consider this code, struct A {}; struct B { B(const A&) {} }; void
Template compilation error using pointer of pointer: (What causes the code not to compile
This code causes a Segmentation Fault: int main(){ char *p; char a[50] = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
I have the following code: if (include_once(dirname(__FILE__).'/file.php') || include_once(dirname(__FILE__).'/local/file.php') ) { This causes an
This code below allows me to find the word error in all my files
using the following code, all cause a compilation error (.net 2): var headers =
Eclipse always gives me this compilation error when I try to get the length
Does this code cause a memory leak: int main(){ int * a = new
Can anyone please suggest me whether this code will cause concurrency or not. This
I have this code: <script id=toModify > Invalid javascript that will cause errors </script>

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.