Skip to content

Comments at end of concatenation macro cause error #5079

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

Open
jrt999 opened this issue Jun 27, 2016 · 5 comments
Open

Comments at end of concatenation macro cause error #5079

jrt999 opened this issue Jun 27, 2016 · 5 comments
Labels
IDE 1.9.x Beta Related to the Arduino IDE Beta Build Type: Bug

Comments

@jrt999
Copy link

jrt999 commented Jun 27, 2016

A concatenation macro having a comment at end of same line causes Arduino IDE to fail - appears to be when it is "pasting" for indexing source code. CPP processes the file fine.

Example code

# define RXN 2  /* comment here causes error: pasting ... does not give valid preprocessing token */
# define RXN_BUFHEAD(X)        Rx ## X ## _BufHead
# define Rxn_BUFHEAD(X)        RXN_BUFHEAD(X)
# define Rxn_BufHead           Rxn_BUFHEAD(RXN)

static uint8_t   Rxn_BufHead;  // User read steps on, then takes from buffer

void setup() {

  Rx2_BufHead = 0;
}

void loop() {
}
@thinkyhead
Copy link

thinkyhead commented Feb 26, 2018

Seeing this again in Arduino IDE 1.9 beta.
See the issue linked above, for example.
End-of-line comments are converted into block comments and retained as part of the token value instead of being stripped.

sketch\src\module\thermistor/../../inc/../pins/pins_RADDS.h:143:31: error:
pasting "/* BED*/" and "_WPORT" does not give a valid preprocessing token

 #define HEATER_BED_PIN      7 // BED
                               ^

sketch\src\module\thermistor/../../inc/../HAL/HAL_DUE/fastio_Due.h:75:33: note: in definition of macro '_WRITE'
   volatile Pio* port = (DIO ##  IO ## _WPORT); \
                                 ^

sketch\src\module\thermistor/../../inc/Conditionals_post.h:850:31: note: in expansion of macro 'WRITE'
   #define WRITE_HEATER_BED(v) WRITE(HEATER_BED_PIN, (v) ^ HEATER_BED_INVERTING)
                               ^

sketch\src\module\thermistor/../../inc/Conditionals_post.h:850:37: note: in expansion of macro 'HEATER_BED_PIN'
   #define WRITE_HEATER_BED(v) WRITE(HEATER_BED_PIN, (v) ^ HEATER_BED_INVERTING)
                                     ^

sketch\src\module\temperature.cpp:877:11: note: in expansion of macro 'WRITE_HEATER_BED'
           WRITE_HEATER_BED(LOW);
           ^

@matthijskooijman
Copy link
Collaborator

matthijskooijman commented Feb 26, 2018

Interesting isue. From the error in the last comment, it seems that the preprocessor is converting the // BED comment to /* BED */ so it does not cause issues in most contexts, except for this one.

It does seem this is a compiler bug. From the C++11 (draft) spec (2.2.3):

The source file is decomposed into preprocessing tokens (2.5) and sequences of white-space characters (including comments). A source file shall not end in a partial preprocessing token or in a partial comment. Each comment is replaced by one space character.

This happens before processing preprocessing tokens, so the code shown should compile.

However, I'm not able to reproduce this error with any of the compilers I have at hand here. I do not have the 1.9 beta installed, but I do not believe the arm gcc version is changed there. @thinkyhead, could you show a more self-contained example (or test the example from @jrt999 in your setup) and provide some more details about your setup (what board/core are you using, what core version) and a full verbose compile output (enable in preferences) would also help in reproducing this.

@per1234
Copy link
Collaborator

per1234 commented Feb 26, 2018

It sounds to me like arduino/arduino-preprocessor#6

EDIT: I'm referring to the issue reported by thinkhead, which only occurs with Arduino IDE 1.9.0 Beta. The code supplied by jrt999 causes an error in Arduino IDE 1.8.5 as well as 1.9.0 beta

@thinkyhead
Copy link

thinkyhead commented Feb 26, 2018

Here's a branch of Marlin that should exhibit the issue on build (for RADDS/DUE),
assuming nothing else is exacerbating it:
https://github.com/thinkyhead/Marlin/tree/bf2_radds_pin_error

@facchinm facchinm added the IDE 1.9.x Beta Related to the Arduino IDE Beta Build label Jul 16, 2018
@jt-github
Copy link

This is also an issue in v1.8.9 (also found by trying to compile Marlin, like @thinkyhead)

Example (from https://github.com/MarlinFirmware/Marlin/tree/bugfix-2.0.x/Marlin/src/pins/mega/pins_GT2560_V3.h, line 141):
#define SUICIDE_PIN 54 // This pin must be enabled at boot to keep power flowing

Yields:
error: pasting "/* This pin must be enabled at boot to keep power flowing*/" and "_DDR" does not give a valid preprocessing token

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IDE 1.9.x Beta Related to the Arduino IDE Beta Build Type: Bug
Projects
None yet
Development

No branches or pull requests

6 participants