ezieragabriel / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

Stop changing my code #1112

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The Arduino development environment makes a series of modifications to the code 
provided by the user, presumably as a user-friendly gesture towards those who 
can't code proper C++.

The problem is that people who actually know C++ and write sketches (?) on 
accordance are having a lot of pain with those "user-friendly" source code 
transformations. Basically, the Arduino IDE turns perfectly valid C++ programs 
into incorrect ones.

A glaring example is the automatic generation of function prototypes, which are 
fundamentally broken. Even the recent patch mentioned in

http://code.google.com/p/arduino/issues/detail?id=973

falls short on the presence of functions with default arguments, and I suspect 
that it fails too when the function signature spans over several lines.

C++ syntax is really complex and automatic generation of prototypes won't work 
unless you implement a good chunk of a C++ parser, which is unlikely to happen 
if reasonable at all.

So I suggest allowing some sort of flag in the source code of those sketches 
for indicating "I'm a C++ programmer. Honest!" and stopping the Arduino IDE 
from messing with the code. Switching off prototype generation to begin with, 
although not prepending the code with the standard Arduino headers would be 
good too for avoiding problems with line numbers of compiler reports, see

http://code.google.com/p/arduino/issues/detail?id=455

I realize that not adding those headers could pose maintenance problems for the 
user when the Arduino developers decide to use a difference preamble, but we 
are talking about real C++ developers and they can quickly figure out what the 
problem is on that case.

Something like

#pragma arduino-literal-C++-code

should be fine. The IDE would inspect the sketch for the presence of that text 
and switch off the related features.

Original issue reported on code.google.com by o...@wanadoo.es on 14 Nov 2012 at 9:18

GoogleCodeExporter commented 9 years ago
I think you can put your code in a .cpp file, and it will no longer get the 
transformations you complain about.  (Leave a skeleton structure in your .ino 
file to make the IDE happy.)

Original comment by wes...@gmail.com on 14 Nov 2012 at 9:25

GoogleCodeExporter commented 9 years ago
Thanks! That's good enough for me. Close if you wish.

Original comment by o...@wanadoo.es on 14 Nov 2012 at 9:49

GoogleCodeExporter commented 9 years ago
Cool.  As westfw says, we usually suggest that if you want untouched C++ code 
to write it in a separate .cpp file in your sketch.

Original comment by dmel...@gmail.com on 14 Nov 2012 at 2:02

GoogleCodeExporter commented 9 years ago
BTW, maybe it is a good idea to mention the possibility of using .cpp files on 
this section of the troubleshooting guide:

http://arduino.cc/en/Guide/Troubleshooting#toc22

It explains what the problem is, but gives little advice on solving the it. 
Using a .cpp file is a definitive solution (except for those beginners who 
don't know what a function prototype is.)

Original comment by o...@wanadoo.es on 14 Nov 2012 at 6:33