Ujjwal
Ujjwal

Reputation: 151

What is the linkage of `main( )` in g++

As per ISO_14882_2014's, 3.6.1 Main function [basic.start.main]

The linkage (3.5) of main is implementation-defined.

What is its linkage for g++ as g++'s official document does not seem to have this information.

Upvotes: 2

Views: 171

Answers (2)

darune
darune

Reputation: 10972

This is to prevent you from accidentally calling your main function - or writing a 'wrong' main function.

The function main shall not be used within a program. The linkage (3.5) of main is implementation-defined. A program that defines main as deleted or that declares main to be inline, static, or constexpr is ill- formed. The name main is not otherwise reserved.

Upvotes: 0

P.W
P.W

Reputation: 26800

It is not directly mentioned in the manual, but in the chapter on "GCC Command Options" we have this:

-Wmain Warn if the type of main is suspicious. main should be a function with external linkage, returning int, taking either zero arguments, two, or three arguments of appropriate types. This warning is enabled by default in C++ and is enabled by either ‘-Wall’ or ‘-Wpedantic’.

[Emphasis Added]

From this we can infer that the linkage for main in this implementation is external.

Upvotes: 2

Related Questions