Skip to content

Commit ef7de90

Browse files
jjuhltexus
authored andcommitted
Return EXIT_SUCCESS/EXIT_FAILURE from main()
The macros exist for a reason; not all systems use the same integer values to signal success or failure. Although all systems that TGUI currently supports use a 0 return from main to indicate success and everything else as failure, that's not universal. For example, VMS uses 1 to indicate success. In the future TGUI may be ported to systems where the EXIT_SUCCESS/EXIT_FAILURE macros are relevant, so that's one reason to use them and also; they are just a lot more expressive/readable and make perfectly clear what's being returned, so that's another reason to use them.
1 parent ecacf92 commit ef7de90

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

gui-builder/src/main.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2424

2525
#include <TGUI/Config.hpp>
26+
#include <cstdlib>
2627
#ifdef TGUI_SYSTEM_WINDOWS
2728
#include <TGUI/extlibs/IncludeWindows.hpp> // GetCommandLineW
2829
#include <shellapi.h> // CommandLineToArgvW
@@ -78,17 +79,17 @@ int main(int, char* argv[])
7879
catch (const tgui::Exception& e)
7980
{
8081
std::cerr << "TGUI exception thrown: " << e.what() << '\n';
81-
return 1;
82+
return EXIT_FAILURE;
8283
}
8384
catch (const std::exception& e)
8485
{
8586
std::cerr << "Exception thrown: " << e.what() << '\n';
86-
return 1;
87+
return EXIT_FAILURE;
8788
}
8889
catch (...)
8990
{
9091
std::cerr << "Unknown exception thrown\n";
91-
return 1;
92+
return EXIT_FAILURE;
9293
}
93-
return 0;
94+
return EXIT_SUCCESS;
9495
}

tests/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ int main(int argc, char * argv[])
530530

531531
session.cli(cli);
532532
if (session.applyCommandLine(argc, argv) != 0)
533-
return 1;
533+
return EXIT_FAILURE;
534534

535535
std::unique_ptr<TestsWindowBase> window;
536536
if (selectedBackend.empty())
@@ -585,7 +585,7 @@ int main(int argc, char * argv[])
585585
if (!window)
586586
{
587587
std::cerr << "Backend parameter was provided but no matching backend was enabled TGUI\n";
588-
return 1;
588+
return EXIT_FAILURE;
589589
}
590590
}
591591

0 commit comments

Comments
 (0)