Arduino Forum

Using Arduino => Microcontrollers => Topic started by: falcon74 on May 14, 2013, 03:27 pm

Title: Arduino IDE's -- 'C' code generation and intermediate files
Post by: falcon74 on May 14, 2013, 03:27 pm
Is it possible to somehow intercept the IDE's build process, to isolate the intermediate 'C' files which use the avr-libc (and other Arduino libs), to study ?
Title: Re: Arduino IDE's -- 'C' code generation and intermediate files
Post by: fungus on May 14, 2013, 03:56 pm
Why bother when it's all open source and downloadable?

http://www.nongnu.org/avr-libc/

Title: Re: Arduino IDE's -- 'C' code generation and intermediate files
Post by: falcon74 on May 14, 2013, 04:09 pm
Should have worded my requirement and motivation more clearly.
What I'd like to do, while I am learning to program directly with avr-libc, is to compare / try-understand the Arduino (Java/C++ based) converted to C code, generated by IDE as a result of compile+verify step.
Title: Re: Arduino IDE's -- 'C' code generation and intermediate files
Post by: westfw on May 14, 2013, 04:16 pm
The pre-processed files generated by the Arduino IDE show up in the (java-determined) tmp directory that you can see if you turn on verbose compilation in the Arduino preferences, and you can look at them there.

Note that there is generally quite a bit less pre-processing than you seem to expect.  An arduino sketch is C++ code, and the main thing that happens is that the IDE generates a set of function prototypes at the beginning of the code, before passing it to a real C++ compiler.  There is no "conversion to C" step.
Title: Re: Arduino IDE's -- 'C' code generation and intermediate files
Post by: fungus on May 14, 2013, 04:33 pm

Should have worded my requirement and motivation more clearly.
What I'd like to do, while I am learning to program directly with avr-libc, is to compare / try-understand the Arduino (Java/C++ based) converted to C code, generated by IDE as a result of compile+verify step.


There's no conversion to C. The compiler accepts C++ directly and there's no Java.

Title: Re: Arduino IDE's -- 'C' code generation and intermediate files
Post by: SirNickity on May 14, 2013, 08:53 pm
This article was helpful when I had the same question:

http://arduino.cc/en/Hacking/BuildProcess

The short of it being, the IDE tidies up the sketch by merging all tabs into one file, adding prototypes, including library files in the build, and so on.  But that's about it.  Most of the "magic" is actually just C++ wrappers to add friendly functions and defines so you don't have to know so much about the hardware registers.

Moving to AVR C is fairly easy to do with Atmel Studio.  You can even import the Arduino libs and write your programs in a "real" C++ IDE.  That's actually a good way to go, because IMO, the Arduino IDE is really a horrible code editor, but the platform is so handy. :P