barjac
July 22, 2022, 2:28pm
1
I am using Serial for debug only (or I thought I was) but I find that my #ifdef conditionals are being ignored and on opening a serial monitor the 'debug' Serial commands are being compiled.
Here is a short test example:
//========================
void setup() {
//#define SERIAL
#ifdef SERIAL
Serial.begin(115200);
#endif
}
void loop() {
#ifdef SERIAL
Serial.println("Hello");
#endif
delay(1000);
}
//===========================
Note that "#define SERIAL" is commented, but the serial monitor displays Hello
Hello
. . . .
Is it me, or is the compiler broken?
IDE 1.8.16 running on Linux.
Maybe you're demonstrating that SERIAL is already a define, somewhere in the Arduino setup itself prior to your code? Maybe, use SERL instead of a very commonly used word like SERIAL?
Just a suggestion, as I have no time to test this. Gotta Run!
C
barjac
July 22, 2022, 2:38pm
3
Thanks!
I purposely used all upper case to hopefully avoid any 'reserved' words, but you are correct, using 'SER' instead of SERIAL has resolved the issue.
If you uncomment the #define , you will get a warning
C:\Users\sterretje\AppData\Local\Temp\arduino_modified_sketch_825645\sketch_jul22a.ino:3:0: warning: "SERIAL" redefined
#define SERIAL
In file included from sketch\sketch_jul22a.ino.cpp:1:0:
C:\Users\sterretje\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\cores\arduino/Arduino.h:54:0: note: this is the location of the previous definition
#define SERIAL 0x0
barjac
July 23, 2022, 10:05am
5
You get a warning, but I don't. If I had seen a warning I would have realized the cause.
There is no warning even with verbose set in preferences.
Full verbose output below:
/home/baz/Downloads/arduino-1.8.16/arduino-builder -dump-prefs -logger=machine -hardware /home/baz/Downloads/arduino-1.8.16/hardware -tools /home/baz/Downloads/arduino-1.8.16/tools-builder -tools /home/baz/Downloads/arduino-1.8.16/hardware/tools/avr -built-in-libraries /home/baz/Downloads/arduino-1.8.16/libraries -libraries /home/baz/Arduino/libraries -fqbn=arduino:avr:nano:cpu=atmega328 -ide-version=10816 -build-path /tmp/arduino_build_232300 -warnings=none -build-cache /tmp/arduino_cache_408604 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=/home/baz/Downloads/arduino-1.8.16/hardware/tools/avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=/home/baz/Downloads/arduino-1.8.16/hardware/tools/avr -prefs=runtime.tools.avrdude.path=/home/baz/Downloads/arduino-1.8.16/hardware/tools/avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=/home/baz/Downloads/arduino-1.8.16/hardware/tools/avr -prefs=runtime.tools.arduinoOTA.path=/home/baz/Downloads/arduino-1.8.16/hardware/tools/avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=/home/baz/Downloads/arduino-1.8.16/hardware/tools/avr -verbose /home/baz/Arduino/sketch_jul23a/sketch_jul23a.ino
/home/baz/Downloads/arduino-1.8.16/arduino-builder -compile -logger=machine -hardware /home/baz/Downloads/arduino-1.8.16/hardware -tools /home/baz/Downloads/arduino-1.8.16/tools-builder -tools /home/baz/Downloads/arduino-1.8.16/hardware/tools/avr -built-in-libraries /home/baz/Downloads/arduino-1.8.16/libraries -libraries /home/baz/Arduino/libraries -fqbn=arduino:avr:nano:cpu=atmega328 -ide-version=10816 -build-path /tmp/arduino_build_232300 -warnings=none -build-cache /tmp/arduino_cache_408604 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=/home/baz/Downloads/arduino-1.8.16/hardware/tools/avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=/home/baz/Downloads/arduino-1.8.16/hardware/tools/avr -prefs=runtime.tools.avrdude.path=/home/baz/Downloads/arduino-1.8.16/hardware/tools/avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=/home/baz/Downloads/arduino-1.8.16/hardware/tools/avr -prefs=runtime.tools.arduinoOTA.path=/home/baz/Downloads/arduino-1.8.16/hardware/tools/avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=/home/baz/Downloads/arduino-1.8.16/hardware/tools/avr -verbose /home/baz/Arduino/sketch_jul23a/sketch_jul23a.ino
Using board 'nano' from platform in folder: /home/baz/Downloads/arduino-1.8.16/hardware/arduino/avr
Using core 'arduino' from platform in folder: /home/baz/Downloads/arduino-1.8.16/hardware/arduino/avr
Detecting libraries used...
/home/baz/Downloads/arduino-1.8.16/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/home/baz/Downloads/arduino-1.8.16/hardware/arduino/avr/cores/arduino -I/home/baz/Downloads/arduino-1.8.16/hardware/arduino/avr/variants/eightanaloginputs /tmp/arduino_build_232300/sketch/sketch_jul23a.ino.cpp -o /dev/null
Generating function prototypes...
/home/baz/Downloads/arduino-1.8.16/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/home/baz/Downloads/arduino-1.8.16/hardware/arduino/avr/cores/arduino -I/home/baz/Downloads/arduino-1.8.16/hardware/arduino/avr/variants/eightanaloginputs /tmp/arduino_build_232300/sketch/sketch_jul23a.ino.cpp -o /tmp/arduino_build_232300/preproc/ctags_target_for_gcc_minus_e.cpp
/home/baz/Downloads/arduino-1.8.16/tools-builder/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /tmp/arduino_build_232300/preproc/ctags_target_for_gcc_minus_e.cpp
Compiling sketch...
/home/baz/Downloads/arduino-1.8.16/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/home/baz/Downloads/arduino-1.8.16/hardware/arduino/avr/cores/arduino -I/home/baz/Downloads/arduino-1.8.16/hardware/arduino/avr/variants/eightanaloginputs /tmp/arduino_build_232300/sketch/sketch_jul23a.ino.cpp -o /tmp/arduino_build_232300/sketch/sketch_jul23a.ino.cpp.o
Compiling libraries...
Compiling core...
Using precompiled core: /tmp/arduino_cache_408604/core/core_arduino_avr_nano_cpu_atmega328_000dab1d32415a24d3b364a02571d0fb.a
Linking everything together...
/home/baz/Downloads/arduino-1.8.16/hardware/tools/avr/bin/avr-gcc -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o /tmp/arduino_build_232300/sketch_jul23a.ino.elf /tmp/arduino_build_232300/sketch/sketch_jul23a.ino.cpp.o /tmp/arduino_build_232300/../arduino_cache_408604/core/core_arduino_avr_nano_cpu_atmega328_000dab1d32415a24d3b364a02571d0fb.a -L/tmp/arduino_build_232300 -lm
/home/baz/Downloads/arduino-1.8.16/hardware/tools/avr/bin/avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 /tmp/arduino_build_232300/sketch_jul23a.ino.elf /tmp/arduino_build_232300/sketch_jul23a.ino.eep
/home/baz/Downloads/arduino-1.8.16/hardware/tools/avr/bin/avr-objcopy -O ihex -R .eeprom /tmp/arduino_build_232300/sketch_jul23a.ino.elf /tmp/arduino_build_232300/sketch_jul23a.ino.hex
/home/baz/Downloads/arduino-1.8.16/hardware/tools/avr/bin/avr-size -A /tmp/arduino_build_232300/sketch_jul23a.ino.elf
Sketch uses 1522 bytes (4%) of program storage space. Maximum is 30720 bytes.
Global variables use 194 bytes (9%) of dynamic memory, leaving 1854 bytes for local variables. Maximum is 2048 bytes.
Setting warnings to ALL should work better.
barjac
July 23, 2022, 9:44pm
7
Right. Thanks!
I never noticed that check box, crazy that it is not the default!
I'm not used to using a graphical IDE for this sort of job which is usually done in CLI.
I find the extra GUI layer confusing.
system
Closed
January 19, 2023, 9:45pm
8
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.