Skip to content

Redeclaring main doesn't trigger an error #4826

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

Open
TOTON95 opened this issue Apr 6, 2016 · 6 comments
Open

Redeclaring main doesn't trigger an error #4826

TOTON95 opened this issue Apr 6, 2016 · 6 comments

Comments

@TOTON95
Copy link

TOTON95 commented Apr 6, 2016

Adding "int main = 0;" before setup() deny any TX Data from your arduino, could anybody confirm it please or if you can explain it :D

@TOTON95
Copy link
Author

TOTON95 commented Apr 6, 2016

** Placing it outside of Setup() or Loop() causes it otherwise it doesnt affect

@NicoHood
Copy link
Contributor

NicoHood commented Apr 6, 2016

adding it before setup() is the same as placing it outside setup(). So Your description does not really make sense at all.

Also main is reserved for the main loop hidden by the arduino IDE. Just dont use main as its is a reserved name.

@facchinm
Copy link
Member

Indeed the problem here is about the compiler not emitting any error/warning.
This happens because main() is not declared in any header file, thus the compiler legally compile the sketch and the linker replaces main() implementation with an int.
Adding

int main( void );

to Arduino.h should solve the issue.
@cmaglie @sandeepmistry @matthijskooijman , what do you think about that?

@cmaglie
Copy link
Member

cmaglie commented Jul 19, 2016

@facchinm
looks fine, I can't see any drawbacks.

@TOTON95
Copy link
Author

TOTON95 commented Jul 20, 2016

@facchinm I can see that you reach the issue as i did, and must have a warning at least to prevent it. I fixed it changing the name of the variable.


If you consider that this thread has become irrelevant besides the possible addition of a warning to the compiler, let me know to close it, thank you very much for your answers!

@facchinm facchinm changed the title Add the next line will stop any TX data of your arduino Redeclaring main doesn't trigger an error Jul 20, 2016
@facchinm
Copy link
Member

Let's keep this issue as reference for being closed by the upcoming PR 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
@cmaglie @NicoHood @facchinm @TOTON95 and others