Shop OBEX P1 Docs P2 Docs Learn Events
Main in Cpp File — Parallax Forums

Main in Cpp File

KyeKye Posts: 2,200
edited 2014-12-28 12:47 in Propeller 1
I've noticed that when compiling a .cpp file or a .cogcpp file propeller-elf-g++ enforces main must return an int. Is this because of the -std=gnu++0x flag? The -std=c99 used for the gcc (not g++) doesn't have issues with a void main taking any argument type.

Comments

  • Heater.Heater. Posts: 21,230
    edited 2014-12-28 12:47
    Yep.

    This gives an error even without get the -std=gnu++0x flag if a I specify that main returns void. I have no idea what the default C++ standard is for my g++ on Debian.

    However if I don't put any return type on main() then it compiles OK as the default return type is int.

    Similarly clang++ gives an error if the return type is not int.

    Even better it gives an error if you don't specify a return type, for example:

    hello.cpp:4:2: error: C++ requires a type specifier for all declarations.

    Bottom line is that C and C++ are different languages with different standards and standards bodies.
Sign In or Register to comment.