From ba6c91c8fc0ca7bbf7b8e757e437e7e804583651 Mon Sep 17 00:00:00 2001 From: Michael Park Date: Sun, 13 Dec 2015 16:51:07 +0000 Subject: [PATCH] Swapped the order between `F.50` and `F.46`. --- CppCoreGuidelines.md | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index bcad2a4..a0e4f13 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -2851,6 +2851,28 @@ Better: Flag any use of `&&` as a return type, except in `std::move` and `std::forward`. +### F.46: `int` is the return type for `main()` + +##### Reason + +It's a language rule, but violated through "language extensions" so often that it is worth mentioning. +Declaring `main` (the one global `main` of a program) `void` limits portability. + +##### Example + + void main() { /* ... */ }; // bad, not C++ + + int main() + { + std::cout << "This is the way to do it\n"; + } + +##### Enforcement + +* The compiler should do it +* If the compiler doesn't do it, let tools flag it + + ### F.50: Use a lambda when a function won't do (to capture local variables, or to write a local function) ##### Reason @@ -2884,27 +2906,6 @@ Functions can't capture local variables or be declared at local scope; if you ne * Warn on use of a named non-generic lambda (e.g., `auto x = [](int i){ /*...*/; };`) that captures nothing and appears at global scope. Write an ordinary function instead. -### F.46: `int` is the return type for `main()` - -##### Reason - -It's a language rule, but violated through "language extensions" so often that it is worth mentioning. -Declaring `main` (the one global `main` of a program) `void` limits portability. - -##### Example - - void main() { /* ... */ }; // bad, not C++ - - int main() - { - std::cout << "This is the way to do it\n"; - } - -##### Enforcement - -* The compiler should do it -* If the compiler doesn't do it, let tools flag it - ### F.51: Prefer overloading over default arguments for virtual functions ??? possibly other situations?