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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:30:58+00:00 2026-06-09T04:30:58+00:00

The related C program is below: #include <stdio.h> void testifbarisvisible(); int main() { void

  • 0

The related C program is below:

    #include <stdio.h>

    void testifbarisvisible();

    int main()
    {
            void bar(int);
        bar(1);
        testifbarisvisible();
    }

    void testifbarisvisible()
    {
        bar(2);
    }

    void bar(int x)
    {
        printf("functionbar\n");
    }

The output of gcc is:

% gcc -std=c99 -c /tmp/notfilescope.c
/tmp/notfilescope.c: In function ‘testifbarisvisible’:
/tmp/notfilescope.c:14:2: warning: implicit declaration of function ‘bar’
/tmp/notfilescope.c:7:7: note: previous declaration of ‘bar’ was here
/tmp/notfilescope.c:14:2: error: incompatible implicit declaration of function ‘bar’
/tmp/notfilescope.c:7:7: note: previous implicit declaration of ‘bar’ was here

After I removed the statement in line 7, the output is:

% gcc -std=c99 -c /tmp/notfilescope.c
/tmp/notfilescope.c: In function ‘main’:
/tmp/notfilescope.c:8:2: warning: implicit declaration of function ‘bar’
/tmp/notfilescope.c: At top level:
/tmp/notfilescope.c:17:6: warning: conflicting types for ‘bar’
/tmp/notfilescope.c:8:2: note: previous implicit declaration of ‘bar’ was here

The version of gcc is:

% gcc --version
gcc (GCC) 4.6.3 20120306 (Red Hat 4.6.3-2)
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE

I’m confused about the difference between the two outputs of gcc.

This is from the gcc’s documents, “Declarations of external variables and functions within a block apply only to the block containing the declaration.In other words, they have the same scope as any other declaration in the same place.”

So I think that the function declaration in line 7 has no relationship with the function call in line 14. But the result indicate that opinion was wrong. They are all implicit declaration of function ‘bar’, but one of them leads to error (incompatible implicit declaration of function ‘bar’), and the other one leads to warning (conflicting types for ‘bar’), why?

This question has confused me a long time. Can someone help me?

  • 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-09T04:31:00+00:00Added an answer on June 9, 2026 at 4:31 am

    Within main, bar has only function scope; it is known only within main. However, C has another process called linkage. Per C 1999 6.2.2 1, “An identifier declared in different scopes or in the same scope more than once can be made to refer to the same object or function by a process called linkage.”

    In main, the declaration void bar(int); declares bar with external linkage, per C 1999 6.2.2 5: “If the declaration of an identifier for a function has no storage-class specifier, its linkage is determined exactly as if it were declared with the storage-class specifier extern.”

    Then, in testifbarisvisible, bar is not in scope. The statement bar(2); implicitly declares bar to be external, and, because bar is not in scope, it is an implicit declaration of bar with no prototype. This implicit declaration has a different type than the previous void bar(int);, but, because of linkage, it must refer to the same function. (Per 6.2.2 2, “In… an entire program, each declaration of a particular identifier with external linkage denotes the same object or function.”) This is a conflict, so the compiler produces an error.

    When you remove void bar(int);, there is no explicit declaration of bar in main. Instead, bar is implicitly declaration by the following line, bar(1);. This implicit has the same type as the implicit declaration in testifbarisvisible. Because the declarations are identical, there is no error. The compiler still gives you a warning because implicit declarations are dangerous (because the eventual explicit declaration might be in a different file and might be different, which can cause undiagnosed errors at execution).

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

Sidebar

Related Questions

I have a question regarding the execution of the following program. #include<stdio.h> int main(void)
I keep hearing the statement on most programming related sites: Program to an interface
I am now working on a program for Android which is something related to
i found many related questions here. I have a simple java program . it
How do I include the mono MPAPI libraries in a program? is there a
I get a seg fault for the simple program below. It seems to be
Here is a very small kill related program .The program is executing but am
I am trying to build a network related program in Java. I have previous
In the CoffeeScript program below, I create a subclass of Array which sets two
This question relates to recursion. Consider the program shown below (not my real code,

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.