Go Down

Topic: Fighting Arduino's IDE smartness (Read 605 times) previous topic - next topic

trurl

#5
Nov 13, 2012, 08:53 pm Last Edit: Nov 13, 2012, 09:02 pm by trurl Reason: 1
CrossRoads, PeterH,

I see quite a few C programmers here  :)

In C++, you don't need the typedef for declaring a type while declaring a struct, nor do you need the `struct Boton {...} boton1' or `struct Boton boton1' syntax for declaring instances. Struct basically works the same way as for `class', although with differences like default accessibility level of members and inherited classes/structs.

But I digress. Neither using the typedef trick nor adding a function declaration for `Chequea' just after the type declaration solves the problem.

PaulS

Code: [Select]
struct Boton {
  int pin;
};

void Chequea(struct Boton &b) {
}

void setup() {
}

void loop() {
}

compiles with no problems.

trurl

PaulS,

That's great to know, thanks!

AFAIK the IDE uses avr-g++ 4.7.0 on Linux and 4.3.? on Windows. Both are recent enough to not require the C-ism shown in your code, so I guess that some switch is passed to the compiler that puts it on a special mode. My guess is that such mode is required for compatibility with legacy code that the Arduino or AVR system still uses.

Is there a way to see the complete command that is used to invoke the compiler?

(And is there an option somewhere to change the compiler switches? I'll like to take advantage of some C++11 features.)

PaulS

Quote
Is there a way to see the complete command that is used to invoke the compiler?

Look at the File + Preferences dialog.

Quote
And is there an option somewhere to change the compiler switches?

Not using the IDE.

trurl

Quote
Look at the File + Preferences dialog.


Ok, marking the "Show verbose output during compilation" checkbox makes the trick.

The compiler is fine, there is no fancy switch passed to it. The problem is the Arduino IDE prepending the user's source code with the auto generated declarations. This is what observed:


  • Writing a declaration makes no difference: the IDE generates a declaration anyways.

  • Since the declaration generated by the IDE is placed at the top of the source file that is actually passed to the compiler, any user-defined type is undefined at the point the declaration is parsed.

  • The idiom `void foo(struct S&)' is accepted because it contains a declaration of `S' as an struct.'



Quote
Not using the IDE.


Ok. I looked at the preferences.txt file and even experimented with a few suspects, but there is nothing there that achieves what I want. So I guess that the only way of adding a switch to the the compiler command is altering the source code of the IDE.

Thanks again PaulS.

Go Up