Pages: [1]   Go Down
Author Topic: How Arduino IDE pre-processing work?  (Read 561 times)
0 Members and 1 Guest are viewing this topic.
Brazil
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Quote
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?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 308
Posts: 26472
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 52
Posts: 2365
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Mark
Logged

Cincinnati, OH
Online Online
God Member
*****
Karma: 49
Posts: 855
I'm not bossy...I just know what you should be doing.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
#define MAXARRAYSIZE  100

If you have an expression in your code that reads:

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

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

Code:
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:

Code:
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:

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

so when you write:

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

the preprocessor expands it to:

Code:
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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50111
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Cincinnati, OH
Online Online
God Member
*****
Karma: 49
Posts: 855
I'm not bossy...I just know what you should be doing.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Brazil
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Edison Member
*
Karma: 33
Posts: 1468
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Brazil
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 308
Posts: 26472
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Brazil
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Pages: [1]   Go Up
Jump to: