Skip to content

Commit a25b56b

Browse files
authored
Create basic_start.md
1 parent e51d22a commit a25b56b

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Diff for: basic_start.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
- A hosted implementation shall contain a global function called main in one of the specified forms *\[basic.start.main\]*
3+
- 6.8.3.1
4+
- Example:
5+
6+
```cpp
7+
void main() {}
8+
```
9+
- Rationale:
10+
11+
- Tools
12+
- [Compiler static analysis, generates warnings or errors for void main](https://wandbox.org/permlink/9YlvHEA88lS0CbvV)
13+
14+
- The function main shall not be used within a program *\[basic.start.main\]*
15+
- 6.8.3.1
16+
- Examples:
17+
- [Is it illegal to take address of main() function?](https://stackoverflow.com/q/15525613/1708801)
18+
- [Why does gcc warn about decltype(main()) but not clang?](https://stackoverflow.com/q/25297257/1708801)
19+
20+
```cpp
21+
printf( “%p\n”, &main ) ;
22+
decltype(main()) x = 0;
23+
```
24+
25+
```cpp
26+
int main() {
27+
std::cout << reinterpret_cast<void*>(&main) ;
28+
}
29+
```
30+
31+
- Tools
32+
- [Compiler static analysis via -pedantic flag gcc/clang for taking address of main](https://wandbox.org/permlink/atm7dJ1LXaVBkCsU)
33+
- [Compiler static analysis via -pedantic flag gcc/clang decltype main](https://wandbox.org/permlink/WvPFbU4hteDOX4w2)
34+
35+
- Rationale:
36+
- From ARM section 3.4 Start and Termination
37+
> This is to ensure full freedom of the implementation of the interface between a C++ program and its environment.
38+
> One could imagine an implementation where main() was not implemented as a function.
39+
- [\[ub\] What does "The function main shall not be used within a program" mean?](http://www.open-std.org/pipermail/ub/2014-January/000474.html)
40+

0 commit comments

Comments
 (0)