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 106k
  • Answers 106k
  • 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
  • Editorial Team
    Editorial Team added an answer Your query returns you exactly what your ask. Try to… May 11, 2026 at 8:56 pm
  • Editorial Team
    Editorial Team added an answer Look into the Rules Engine functionality that is part of… May 11, 2026 at 8:56 pm
  • Editorial Team
    Editorial Team added an answer The kernel accept so called command-line options, that are text… May 11, 2026 at 8:56 pm

Related Questions

I'm having a little trouble figuring out exactly how const applies in a specific
I think there must be something subtle going on here that I don't know
How can I force a section of code to be executed on my main
The method signature of a Java main method is: public static void main(String[] args)

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.