which C++, and is there a specification of just how the IDE tries to "help" one?

OK... the language used with Arduino is based on C++. Some questions:

Which C++? C++11? An earlier version?

The language reference page doesn't include very much. Does a programmer for Arduino have access to the full C++ language? (The page on integer constants doesn't mention the option of a suffix to indicate unsigned and/or long, nor does the page on floating point constants say anything about using the "f" suffix for float (rather than double) constants. There's nothing on the reference page about declaring one's own classes.) I presume that we don't get to write main() but instead link against a stock main that does something like

startup();
for (; ; ) {
loop();
}

but can one declare one's own classes? Do we have access to templates?

Finally, is there a specification of just what the preprocessing does to try to "help" the programmer (e.g. the bit referred to earlier in the thread about what sounds like trying to automatically generate prototypes for forward references to functions), and is there some way to turn it off? C++ is already insanely convoluted, and I'm not sure I'll be helped by something fiddling with the source code in ways I have yet to find a description of.

http://arduino.cc/forum/index.php/topic,97455.0.html

It's C++.

but can one declare one's own classes? Do we have access to templates?

Yes and yes.

C++ is already insanely convoluted

If you say so.

The IDE generates function prototypes for you. That's about all it does.

(Badly.)

I think it also copies the set of files that it thinks constitutes your complete solution into a temporary directory before it compiles them. The algorithm for selecting the necessary files is imperfect. (This also means that the usual guidelines for using #include file references don't work.)

True. I think the algorithm is roughly this:

  • Scan your main sketch (the .ino file) for #include directives.
  • If they refer to a known "library" (ie. one that it detected when the IDE started) then copy the library (the entire folder I think) to a temporary location.
  • Copy the main sketch to this temporary location and compile from there, with the "include path" set to point to this temporary directory.

Hence in addition to where you might normally put your #include directives they also have to appear in the main sketch to trigger this behaviour.

The advantage of this is that your "sketch" folder is not cluttered with object, hex, elf files etc. Also it is possible to compile and test without even saving your sketch to disk (the copy of your main sketch is from the in-memory copy).

The arduino IDE uses old software, and C++11 is not really at all supported, just a few experimental tidbits: Status of Experimental C++0x Support in GCC 4.3 - GNU Project

You can write your own main, then you don't need setup() and loop(). Just remember to call init() before you use certain Arduino specific features like delay() or millis().

The IDE adding stuff is the price we pay for ease of use. Atmel studio 6 supports gcc 4.6.x, might even be 4.7.x now; and has c++11 support.

If multiple declarations are causing errors ( declared in header, defined in sketch ), inside the sketch just wrap you function declarations in #if blocks that never get entered, then the IDE will see them, but the compiler won't.

pYro_65:
You can write your own main ...

I was not aware of that! Is it documented somewhere?

I don't know about documentation but this compiles:

int main ()
  {
  // whatever
  return 0;  
  }

Certainly...

:smiley:

How did you do that? I can't remember all that stuff ...

jejones3141:
OK... the language used with Arduino is based on C++. Some questions:

Which C++? C++11? An earlier version?

The language reference page doesn't include very much.

There's a link to this on the Arduino Reference page.
http://www.nongnu.org/avr-libc/user-manual/modules.html

Freakishly good memory. (And a bit of Google-sgil.)

Men are vexed by women's phenomenal memory of past transgressions. Despite my good memory, I am too. I guess that means my wife has a super freak memory. :smiley:

How is it on topics other than your transgressions?

Impressive memory there, @Coding Badly :smiley:

And thanks @pYro for bringing it up. Not actually sure of how much practical value it is, but I definitely consider it "good to know!"

GoForSmoke:

[quote author=Coding Badly link=topic=160239.msg1200454#msg1200454 date=1365930503]I guess that means my wife has a super freak memory. :smiley:

How is it on topics other than your transgressions?[/quote]

Her memory is generally super freaky. And, she's strong on technical matters. When we discuss programming or circuits, she can recall long ago but very relevant conversations. I've said it before and I'll say it again, I'm a very fortunate man (as long as I don't get on her bad side :D).