How Arduino IDE pre-processing work?

Hi! I was reading some topics and I found this:

The main sketch is C++, however the IDE does do a certain amount of pre-processing (in particular, generating function prototypes for you) before submitting the code to the main C++ compiler.

Could be found here.

Someone know how this "pre-processing" works? The code is converted to some low level programming language before load the microcontroller with my program? How?

The code is converted to some low level programming language before load the microcontroller with my program?

No, the code is kept as (moderately) high-level C++, but function prototypes are generated, before compilation using avr-gcc.

And a few other things are doe for you such as adding the correct main() ans the standard #include's

Mark

The preprocessor is a "textual" pass through the source code. For example, you've seen something like:

#define MAXARRAYSIZE  100

If you have an expression in your code that reads:

for (i = 0; i < MAXARRAYSIZE; i++) {

when the preprocessor finishes, it's as though you wrote:

for (i = 0; i < 100; i++) {

The advantage, of course, is that you only need to change the #define to everywhere change the affected value in the source code. The preprocessor also reads function prototypes, like:

int myFunction(int val, char *buff);

and constructs an attribute list much like a symbol table that allows it to check all subsequent uses of that function for the correct argument list (i.e., an int and a pointer) and that the return value is used as an int. If also expands any macros you may have written, like:

#define ARRAYSIZE(x)   (sizeof(x) / sizeof(x[0]))

so when you write:

for (i = 0; i <  ARRAYSIZE(buff) ; i++) {

the preprocessor expands it to:

for (i = 0; i <   (sizeof(buff) / sizeof(buff[0])) ; i++) {

I think it helps to simply think of the preprocessor as performing textual replacements, macro expansions, and type checking via prototypes.

The preprocessor is a "textual" pass through the source code.

Which has nothing to do with what the IDE does in terms of processing before it invokes the compiler.

PaulS: I thought OP understood that the IDE and compiler are separate entities. Rereading his post, perhaps not.

econjack:
PaulS: I thought OP understood that the IDE and compiler are separate entities. Rereading his post, perhaps not.

From the original post I got the impression that the OP understood the distinction correctly - the issue is the misguided and poorly implemented mucking about that the IDE does to your code before invoking the compiler, and nothing to do with the C++ compiler / preprocessor.

Thank you all for answer me about preprocessor and sorry about my late response.

So, now that i understand what preprocessor is, what is running inside the ATMEL?

The hex file which gets loaded on the processor contains Atmel machine code. You can read the datasheet for the opcodes.

KeithRB:
The hex file which gets loaded on the processor contains Atmel machine code. You can read the datasheet for the opcodes.

Is there any way to take a look inside the drivers who creates the Atmel machine code?

Is there any way to take a look inside the drivers who creates the Atmel machine code?

The compiler, avr-gcc, is supplied as binary executable, but the sources will be somewhere on the Web.

AWOL:

Is there any way to take a look inside the drivers who creates the Atmel machine code?

The compiler, avr-gcc, is supplied as binary executable, but the sources will be somewhere on the Web.

Thank you. I'll take a look at both datasheet and avr-gcc this week.