Skip to content

[SUGGESTION] Removing special handling of return value of main function #254

Closed
@equeim

Description

@equeim

Currently Cpp2 allows this code:

main: () -> int = {
    std::cout << "Hello \n";
}

I think this code is problematic because it says main function returns an int but it doesn't actually do this. It's especially bad for beginners since one of the first things you would have to explain is why it's allowed here and not in any other place, instead of more substantial things.

Instead I propose allowing to declare main function without return value (and disallowing previous example if it doesn't have return statement):

main: () = {
    std::cout << "Hello \n";
}

It will generate "auto main() -> int" that will return 0.
This way people who start to learn Cpp2 won't immediately ask "why it doesn't return int" (maybe). And the topic of special properties of main function and what forms it can take can be taught later.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions