int32_t main() vs int main()
Asked Answered
R

1

5

I've written a cpp program, and I am able to run it with int32_t main() but not with the signature int main().

Can someone tell me why? Its a .cpp file and not a .c file (as mentioned in some other questions).

Reductive answered 24/8, 2020 at 8:56 Comment(6)
Sounds very strange. Could you post the source code?Fimbriation
Does it happen also for int32_t main() {} vs int main() {}? I mean, with an empty main.Involuntary
Please show a minimal reproducible example and add some details about how you are not able to run it. Does that mean it doesn't compile?Maxfield
int32_t main() {} & int main() both seems to be working fine on OnlineGDB. You need to add more information to your question by editing it.Affined
Which compiler? Platform? What was the error message? etc.Gasser
Apparently it had a weird #define int statement in an included file which was causing this error.Reductive
B
7

The possible explanation could be that one of your #include files at the top redefines int as something else. This may happen if somebody tried to change the data type in some algorithm by simply redefining int.

Try to put #undef int into a line line immediately before the int main() to restore the default meaning of "int".

Brunt answered 24/8, 2020 at 9:25 Comment(3)
Yes, that's the workaround if this abomination is actually what's happening. But it's important to underscore that this situation should never be allowed to arise. +1.Crudden
So can be said about any bug.Fimbriation
Redefining a keyword is not "any bug". There's no good reason to do that, and it makes code unreadable. Not to mention introducing undefined behavior into any but the most trivial programs.Crudden

© 2022 - 2024 — McMap. All rights reserved.