Skip to content

#if bug #1468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lestofante opened this issue Jun 13, 2013 · 6 comments
Closed

#if bug #1468

lestofante opened this issue Jun 13, 2013 · 6 comments
Assignees
Labels
Component: IDE The Arduino IDE Component: Preprocessor The Arduino sketch preprocessor converts .ino files into C++ code before compilation
Milestone

Comments

@lestofante
Copy link

#ifdef __AVR_ATtinyX5__
const byte LED_PIN = 3;   // gamba 2
const byte RECV_PIN = 1;  // gamba 6
#else
const byte LED_PIN = 3;
const byte RECV_PIN = 10;
#endif

give error. declaring a variable before #if resolve the problem.

bug found by nid69ita

@matthijskooijman
Copy link
Collaborator

What kind of error does this give? The code looks good to me?

@lestofante
Copy link
Author

just copy-paste the following code to the ide

#ifdef __AVR_ATtinyX5__
const byte LED_PIN = 3;   // gamba 2
const byte RECV_PIN = 1;  // gamba 6
#else
const byte LED_PIN = 3;
const byte RECV_PIN = 10;
#endif

void setup(){
}

void loop(){
}

compile for any board and you'll get (also tryed with uint8_t):

sketch_jun13a:4: error: 'byte' does not name a type
sketch_jun13a:5: error: 'byte' does not name a type

@matthijskooijman
Copy link
Collaborator

I was going to say that this error doesn't seem related to the #if and you just forgot an include, but the autogenerated #include "Arduino.h" should take care of including/defining those types.

Trying this in the Arduin IDE (1.0.3) confirms the problem. If I remove the #if construct, the code compiles as expected. Looking at the .cpp file the IDE generates from this .ino file, I find it starts with:

matthijs@grubby:~$ cat /tmp/build5957640928641658.tmp/Test2.cpp
#line 1 "Test2.ino"
#ifdef __AVR_ATtinyX5__
#include "Arduino.h"
void setup();
void loop();
#line 2

In other words: The bug is that the IDE inserts the #include after the #if, for some reason. I'm not familiar with the code to find out why this happens, but I guess someone else can take it from here :-)

In the meanwhile, as a workaround you can put some code above the #if statement to make it compile (e.g., something like const int workaround = 0; or something. A #define or a #comment doesn't seem to cut it).

If anyone is looking into this: Perhaps it would be worthwhile to use gcc's -include option to add the Arduino.h include instead of putting it in the generated file?

@ffissore
Copy link
Contributor

Please give a try to the IDEs linked at the bottom of this email on the dev list
https://groups.google.com/a/arduino.cc/forum/#!msg/developers/4X2T3rCxXWM/YNJl6PZuDucJ
We're testing a new preprocessor and it compiles your sketch just fine.

@ffissore ffissore added the Component: Preprocessor The Arduino sketch preprocessor converts .ino files into C++ code before compilation label Jan 28, 2015
@ffissore ffissore self-assigned this Jan 28, 2015
@ffissore
Copy link
Contributor

New preprocessor tracked at #2636. Builds for testing it are available

@ffissore
Copy link
Contributor

Fixed by #3779

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: IDE The Arduino IDE Component: Preprocessor The Arduino sketch preprocessor converts .ino files into C++ code before compilation
Projects
None yet
Development

No branches or pull requests

4 participants