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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:18:48+00:00 2026-06-15T15:18:48+00:00

Suppose the code: extern int foo(void); static int foo(void) { return 0; } Try

  • 0

Suppose the code:

extern int foo(void);

static int foo(void)
{
        return 0;
}

Try to compile with GCC

$ gcc -Wall -std=c99 1.c 
1.c:3:12: error: static declaration of ‘foo’ follows non-static declaration
1.c:1:12: note: previous declaration of ‘foo’ was here
1.c:3:12: warning: ‘foo’ defined but not used [-Wunused-function]

So, how can I declare static function?

  • 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-15T15:18:49+00:00Added an answer on June 15, 2026 at 3:18 pm

    Why declaration by extern doesn’t work with static functions?

    Because extern indicates external linkage while static indicates internal linkage. Obviously, You cannot have both on same function.

    In simple words, when you use static on the function you tell the compiler please limit the scope of this function only to this translation unit and do not allow anyone to access this from another translation unit.
    while function declarations are extern by default, when you specify extern explicitly you tell the compiler, Please allow everyone from other translation units to access this function.
    Well obviously the compiler cannot do both.

    So make a choice, whether you want the function to be visible only in the translation unit or not.
    If former make it static and forget extern. If latter just drop the static.

    Good Read:
    What is external linkage and internal linkage?

    Though above Q is for C++, most of what is discussed applies to C as well.

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

Sidebar

Related Questions

Suppose this code: public class Test{ public static void main(String[] args) { Test.testInt(new int[]{2,3});
Suppose the following code: void SomeClass::SomeMethod() { CComPtr<ISomeService> service = GetService(); ExecuteInNewThread([&]() { service->AnotherMethod();
suppose the code does the following: T *pointer = new T(); delete static_cast<void*>(pointer); what
suppose this code: main() { int *x; *x = 3; printf(%d %d %d\n, *x,
Suppose I created a header file constants.h and this file contains: extern const int
suppose a dll contains the following functions extern C __declspec(dllexport) void f(bool x) {
Suppose code like this: class Base: def start(self): pass def stop(self) pass class A(Base):
Suppose my code is like this: <td class=apple> <div class=worm> text1 </div> </td> <td
I am facing a serious issue with sprintf . Suppose my code snippet is:
How to get generic interface type for an instance ? Suppose this code: interface

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.