Skip to content
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

error: expected identifier before string constant #1978

Closed
dirkt68 opened this issue Oct 3, 2023 · 8 comments
Closed

error: expected identifier before string constant #1978

dirkt68 opened this issue Oct 3, 2023 · 8 comments
Labels
v6 ArduinoJson 6

Comments

@dirkt68
Copy link

dirkt68 commented Oct 3, 2023

Description
Hello everyone,

I am currently using the single header file version of the library to try and do some basic serialization, and unfortunately I am having trouble with some errors coming up. I am assuming it is Visual Studio Code's fault, as the header file compiles fine on Programiz's Online Compiler. There are three spots marked as "errors" but which are valid syntax:

line 589 -> SizedRamString(const char* str, size_t sz) : str_(str), size_(sz) {} -> "expected identifier" (squiggle on the "s" in str_)
line 527 -> ZeroTerminatedRamString(const char* str) : str_(str) {} -> same problem
line 888/889 -> FlashString(const __FlashStringHelper* str, size_t sz) : str_(reinterpret_cast<const char*>(str)), size_(sz) {} -> same problem

Thank you all for your help!

Troubleshooter's report

  1. The program uses ArduinoJson 6
  2. The issue happens at compile time
  3. The error is not in the list

Environment

  • Microcontroller: RAK4631
  • Core/Framework: Latest offical Arduino plugin on Visual Studio Code, WisBlock RUI3 RAK4361 Core
  • IDE: Visual Studio Code Version 1.82.3(user setting)

Reproduction code

#include <ArduinoJson.h>

void setup(){}

void loop(){}

Remarks
This also occurs in a blank project simply by including the header, so I do not believe it is code related. There are also a lot of undefined functions and other errors around the header file, but those three cause red squiggles. As a test, adding this header to a CLion PlatformIO project shows no errors whatsoever and compiles correctly.

@bblanchon
Copy link
Owner

Hi @dirkt68,

Please share the complete compiler output.

Best regards,
Benoit

@bblanchon
Copy link
Owner

I compiled JsonGeneratorExample.ino successfully with the following setup:

I only had to add #include <Adafruit_TinyUSB.h> at the top of the file.

@dirkt68
Copy link
Author

dirkt68 commented Oct 4, 2023

Benoit,

Thank you for responding so quickly, I am attaching the compiler output from the most recent one, apologies for the length.
compiler_output.txt

I am using the same version of the Arduino IDE, and I think there might be a difference between your test and my environment, as my FQBN is rak_rui:nrf52:WisCoreRAK4631Board, not rakwireless:nrf52:WisCoreRAK4631Board. RAK Wireless has two different methods of using their boards in Arduino, so maybe the rui version could be causing this issue? I tried compiling this file in a random ESP32 sketch and that worked fine on the same Arduino IDE.

Thank you for your time,
Dirk

@bblanchon bblanchon changed the title ArduinoJSON unable to be compiled error: expected identifier before string constant Oct 4, 2023
@bblanchon
Copy link
Owner

bblanchon commented Oct 5, 2023

Hi Dirk,

I could not install the RUI boards on the Arduino IDE.
I used the following boards url, but it didn't add any new boards to the IDE:
https://github.com/RAKWireless/RAKwireless-Arduino-BSP-Index/blob/main/package_rakwireless_index.json

How did you do?

Best regards,
Benoit

@bblanchon
Copy link
Owner

I was able to reproduce the issue by adding the following line at the top of the file:

#define str_(s) #s

I found this macro in:

@dirkt68
Copy link
Author

dirkt68 commented Oct 5, 2023

Oh wow, would adding a check and #undef solve the issue if put in the header?

@bblanchon
Copy link
Owner

As a workaround, you can #undef, but it's better to rename the macro.
I'll open issues on the corresponding repos.

@dirkt68
Copy link
Author

dirkt68 commented Oct 5, 2023

Benoit,

Thanks so much for your quick help with all of this, renaming all instance of str_ in ArduinoJson.h to str_json_ solves the problem for me. While not the permanent solution of course, this will do for me!

Sincerely,
Dirk

@dirkt68 dirkt68 closed this as completed Oct 5, 2023
bblanchon added a commit to bblanchon/ArduinoJsonTroubleshooter that referenced this issue Oct 6, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 5, 2023
@bblanchon bblanchon added the v6 ArduinoJson 6 label Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
v6 ArduinoJson 6
Projects
None yet
Development

No branches or pull requests

2 participants