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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:27:14+00:00 2026-05-29T22:27:14+00:00

This code is just a situation that I found in my actual code which

  • 0

This code is just a situation that I found in my actual code which is very big so I’m giving this.here in this code the structure “struct node” is not defined it is defined in another c source file.

my c source code:

/* test.c */

  1 #include<stdio.h>
  2 #include "test2.h"
  3
  4 void f(struct node * k)
  5 {
  6   
  7 }

my header file :

/* test2.h */

  1 extern void f(struct node * k);

When I compile this code with gcc to create an object file:

gcc -w -c test.c

I get:

test.c:6: error: conflicting types for 'f'
test2.h:1: error: previous declaration of 'f' was here

I have given the complete prototype of function f(). Why I am getting this error?

Another thing is that when I don’t include the header file test2.h in test.c and explicitly declare the function prototype in test.c, it compiles successfully. Code is below:

 /* test.c */

      1 #include<stdio.h>
      2 void f(struct node *k);
      3
      4 void f(struct node * k)
      5 {
      6
      7 }

gcc -c -w test.c

No error.

Can you please explain why this time I am not getting an error?

  • 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-29T22:27:15+00:00Added an answer on May 29, 2026 at 10:27 pm

    This has nothing to do with the extern keyword on the prototype (although it’s not necessary).

    You need a forward declaration for struct node:

    /* test2.h */
    
    struct node;  // <== this
    
    extern void f(struct node * k);
    

    Without that forward declaration, the struct node inside the function prototype is local to that particular function prototype.

    So when the compiler sees the definition of f() it also sees another different local declaration for a struct node and thinks that you have a conflicting declaration for f().

    See C99 6.9.1 “Scopes of identifiers”:

    For each different entity that an identifier designates, the
    identifier is visible (i.e., can be used) only within a region of
    program text called its scope. Different entities designated by the
    same identifier either have different scopes, or are in different name
    spaces. There are four kinds of scopes: function, file, block, and
    function prototype. (A function prototype is a declaration of a
    function that declares the types of its parameters.)

    …

    If the declarator or type specifier that declares the identifier
    appears within the list of parameter declarations in a function
    prototype (not part of a function definition), the identifier has
    function prototype scope, which terminates at the end of the function
    declarator.

    GCC 4.6.1 gives a nice warning about this for me:

    C:\temp\test.c:3:22: warning: 'struct node' declared inside parameter list [enabled by default]
    C:\temp\test.c:3:22: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]
    

    C++ makes function prototype scope apply only to the parameter names (C++03 3.3.3), so you won’t see this problem if you compile the code as C++.

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

Sidebar

Related Questions

I just found this code in reflector in the .NET base libraries... if (this._PasswordStrengthRegularExpression
I recently found a situation in which I had two related variables that had
I am working on const-correctness of my code and just wondered why this code
this code in my plugin used to work just fine: jQuery('#embedded_obj', context).get(0).getVersion(); and the
I just came across this code and a few Google searches turn up no
This code does not seem to compile, I just need to write something to
I just saw this code while studying the wordpress source code (PHP), You can
is it just me or this code in Programming Pearls is wrong (quicksort wants
I have just come across this code: function test(){ //... if ( $profilerule ==
I was just looking at this code and i don't understand what RETURN TRUE

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.