In How to stringify a string which contains a comma? it is described how to stringify a string.
However, it does not work with specials characters, for instance:
#include <Arduino.h>
#define TOSTR_(...) #__VA_ARGS__
#define STRINGIFY(...) TOSTR_(__VA_ARGS__)
const char htmlRootPage[] PROGMEM =
STRINGIFY(<input name="txtGt" type="number" value="39.5" max="42" step="0.5" style="width:160px;">°C<br>)
;
void setup() {
}
void loop() {
}
Here the degree char ° is not valid, I get
6:99: error: extended character ° is not valid in an identifier
6 | STRINGIFY(<input name="txtGt" type="number" value="39.5" max="42" step="0.5" style="width:160px;">°C<br>)
| ^
exit status 1
extended character ° is not valid in an identifier
Just to try, when I replace the degree char, with:
ρΨψλω àäâéèêëïîöôóíùüû ES_áñ DE_ß HU_őű NOK_åæø CZK_úůýžáčďéěíňóřšť PL(check accent)_ąćęłńśźż RO_ăâîşșţ RU_ёяшертыуиопющэъжьлкйчгфдсазхцвбнм
it does compile.
However, other any other chars such as
¿¡«»
I do get the same compiler error: extended character is not valid in an identifier.
I may be wrong, but it seems to me it ought to accept any utf-8 character(the above example with European non english characters shows it does) until it match the end parenthesis of the STRINGIFY preprocessor statement, but oddly some chars seems to cause issue.
The code is build on ArduinoIDE 1.8.19 https://arduino.github.io/arduino-cli/0.32/sketch-build-process/
Compiler is following:
$ avr-gcc -v
Using built-in specs.
Reading specs from /usr/lib/gcc/avr/12.2.0/device-specs/specs-avr2
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/avr/12.2.0/lto-wrapper
Target: avr
Configured with: /build/avr-gcc/src/gcc-12.2.0/configure --disable-install-libiberty --disable-libssp --disable-libstdcxx-pch --disable-libunwind-exceptions --disable-linker-build-id --disable-nls --disable-werror --disable-__cxa_atexit --enable-checking=release --enable-clocale=gnu --enable-gnu-unique-object --enable-gold --enable-languages=c,c++ --enable-ld=default --enable-lto --enable-plugin --enable-shared --infodir=/usr/share/info --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --prefix=/usr --target=avr --with-as=/usr/bin/avr-as --with-gnu-as --with-gnu-ld --with-ld=/usr/bin/avr-ld --with-plugin-ld=ld.gold --with-system-zlib --with-isl --enable-gnu-indirect-function
Thread model: single
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (GCC)
Why do you need the macro at all? Can't you simply provide an actual string?
Macro, because it's to serve html page to the server on IoT, most of the html,css,js code is shared, but use of #if #else #end according to the actual physical hardware of IoT devices & sensors.
IoT device are limited particularly with ram(in Kbytes not as PC with Gbytes), I stringify a all html page, I just noticed that oddly some chars are not passing.
So the binary code is then uploaded to an IoT device, not a PC, for execution.
Thanks