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

  • Home
  • SEARCH
  • 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 78125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:56:17+00:00 2026-05-10T20:56:17+00:00

Why main must be declared as if it has external linkage? Why it should

  • 0

Why main must be declared as if it has external linkage?

Why it should not be static?

what is meant by external linkage??

  • 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. 2026-05-10T20:56:18+00:00Added an answer on May 10, 2026 at 8:56 pm

    Because you link the startup files to your program, which contains (usually) assembler code that calls your main. If main were static, that code wouldn’t be able to call main.

    external linkage means that other so-called translation-units can see your symbol declared extern in its own translation-unit. So, your main is extern, and it will have an entry in its translation-units symbol table that states its address. Other translation-units will then be able to jump to that address when they want to call main.

    static linkage means your symbol is strictly translation-unit local. This means other translation units will not be able to see that symbol. Thus, symbols with static linkage can occur in different translation units multiple times, and they won’t clash with each other because they are local.

    Edit: Generally, files generated by the compiler from translation units are specific to that particular compiler. For gcc on linux, often the ELF object format is used. You can view its symbol table using readelf -sW <file>.o (simple test-file below):

    test.c

    void bar(void);  static int foo(void) {     return 1; }  int main(void) {     bar();     return foo(); } 

    Here is the output of readelf:

    Symbol table '.symtab' contains 10 entries:    Num:    Value  Size Type    Bind   Vis      Ndx Name      0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND      1: 00000000     0 FILE    LOCAL  DEFAULT  ABS test.c      2: 00000000     0 SECTION LOCAL  DEFAULT    1      3: 00000000     0 SECTION LOCAL  DEFAULT    3      4: 00000000     0 SECTION LOCAL  DEFAULT    4      5: 00000000    10 FUNC    LOCAL  DEFAULT    1 foo      6: 00000000     0 SECTION LOCAL  DEFAULT    6      7: 00000000     0 SECTION LOCAL  DEFAULT    5      8: 0000000a    36 FUNC    GLOBAL DEFAULT    1 main      9: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND bar 

    You see the main function, and a static foo function, called by main. Also there is a function called which is not defined in the file, but which is defined in another object file. As the object file wasn’t finally linked yet, the functions don’t have final addresses assigned yet. After the final link, these will be arranged into the executable and will have addresses assigned. The object file has entries for calls to not-yet defined functions, so that when the file is linked, those call instructions can have the final addresses stored (readelf -r <file>.o):

    Relocation section '.rel.text' at offset 0x308 contains 1 entries:  Offset     Info    Type            Sym.Value  Sym. Name 0000001c  00000902 R_386_PC32        00000000   bar 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 61k
  • Answers 61k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You should always have some way of exiting cleanly. I'd… May 11, 2026 at 9:49 am
  • added an answer First add a reference to WUApiLib 'C:\windows\system32\Wuapi.dll' Then you can… May 11, 2026 at 9:49 am
  • added an answer WF (without SharePoint) doesn't provide such functionality out of the… May 11, 2026 at 9:49 am

Related Questions

Why main must be declared as if it has external linkage? Why it should
Why are the lists list1Instance and p in the Main method of the below
Why does the code below return true only for a = 1? main(){ int
void foo(void **Pointer); int main () { int *IntPtr; foo(&((void*)IntPtr)); } Why do I
I wanna add server controls by using javascript. The main purpose of why I
Why are the British confused about us calling bread rolls “biscuits” when they call bread rolls “puddings”?
Why are SQL distributions so non-standard despite an ANSI standard existing for SQL? Are
Why does Visual Studio declare new classes as private in C#? I almost always
Why is the following C# code not allowed: public abstract class BaseClass { public
Why does C#.Net allow the declaration of the string object to be case-insensitive? String

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.