-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SUGGESTION] Removing special handling of return value of main function #254
Comments
Only loosely related to this issue, but cpp2 could also easily allow other variants for main's signature, such as:
|
Why stop there, span<string_view>?
On 10 February 2023 13:02:07 Michael Cook ***@***.***> wrote:
Only loosely related to this issue, but cpp2 could also easily allow other variants for main's signature, such as:
main: (std::span<char*> args) = {
—
Reply to this email directly, view it on GitHub<#254 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AALUZQKMZPYYEY2T5UQZGOLWWY34ZANCNFSM6AAAAAAUWRZYMA>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
@MichaelCook & @SebastianTroy it was already discussed here: #63 (comment) and here #45 (comment) |
I think this suggestion would be easier to implement than changing main's arguments. You already can't declare |
Limiting the discussion to the return type: Yes, currently all named functions default to returning (I do it by just emitting Cpp2 Thanks! |
For example, this is now a complete legal program in pure Cpp2 (with `-p`) with fully conformant Cpp1 code gen: `main: () = std::cout << "Hello world";`
Currently Cpp2 allows this code:
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):
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.
The text was updated successfully, but these errors were encountered: