Skip to content

IDE doesn't honor preprocessor conditionals when including libraries #1841

Closed
@ghost

Description

In the Arduino IDE 1.5.5, the default sketch on the Uno compiles to 466 bytes:

//this compiles to 466 bytes
void setup() {
}

void loop() {
}

Including Servo.h, it compiles to 1104:

//this compiles to 1104 bytes
#include <Servo.h>

void setup() {
}

void loop() {
}

I would therefore expect the following code to compile to 466 bytes, but this is not the case:

//this compiles to 1104 bytes even though Servo.h should not be included
#ifdef SOME_MACRO_THAT_IS_NOT_DEFINED
#include <Servo.h>
#endif

void setup() {
}

void loop() {
}

However, commenting out the include statements does prevent the library from being included:

//this compiles to 466 bytes as expected
//#ifdef SOME_MACRO_THAT_IS_NOT_DEFINED
//#include <Servo.h>
//#endif

void setup() {
}

void loop() {
}

This caused some headache for me as I tried to figure out why my sketch size was so large despite not including any libraries. This is not the behavior I think anyone would expect from the IDE.

Metadata

Metadata

Assignees

Labels

Component: IDEThe Arduino IDEComponent: PreprocessorThe Arduino sketch preprocessor converts .ino files into C++ code before compilation

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions