Predefined Preprocessor variables

Is there a list somewhere of the predefined Preprocessor variables (eg.: AVR_ATmega2560) that are available in set by the compiler or preprocessor?

I would have a look at Arduino.h, but maybe there is better documentation somewhere.

Set up verbose compilation, and copy the compile command for your sketch.
PERHAPS the defines that are most useful are there in the command line?

If not, in a terminal window precede the compile command with echo | and replace the input and output file specs with -dM -E -x c++ - >tempfile, and then look at tempfile. Warning - it'll have about 500 lines, mostly consisting of internal gcc stuff.

For example, if I compile blink on my mac, I see:

Compiling sketch...
/Applications/Arduino-1.8.15.app/Contents/Java/portable/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -Wall -Wextra -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -I/Applications/Arduino-1.8.15.app/Contents/Java/portable/packages/arduino/hardware/avr/1.8.5/cores/arduino -I/Applications/Arduino-1.8.15.app/Contents/Java/portable/packages/arduino/hardware/avr/1.8.5/variants/mega /tmp/Arduino1.8.15Build/sketch/Blink.ino.cpp -o /tmp/Arduino1.8.15Build/sketch/Blink.ino.cpp.o
Compiling libraries...

Deleting the bold part and adding the extra options gives me:

It took me awhile to find Arduino.h; it only defines (or undefines) a handful of variables, mostly including other .h files.

While that would certainly tell me what variables are defined, it won't tell the conditions that cause them to be defined (or undefined) or their purpose.

I presumed you would be interested in the lines that contain the keyword defined or ifdef.

[Solution involving -Md]

While that would certainly tell me what variables are defined, it won't tell the conditions that cause them to be defined (or undefined) or their purpose.

In that case, I do not believe that such a list exists.

Generally, since there is no way to set pre-processor definitions from the Arduino IDE, the code does not make much use of such options, other than the CPU type defined by the compiler itself, and the peripherals defines like:

#if defined(TCCR3A) && defined(COM3A1)
 // code to support timer3

In fact, a quick look at the output from grep -R "#if" from the hardware/avr directory shows NOTHING that resembles a user-settable option.

(there are other ways of controlling stuff. Much per-platform config is in the .../variants/* files.)

the -D defines are from platform.txt and boards.txt and depend on the board selected in Tools menu.
https://arduino.github.io/arduino-cli/0.23/platform-specification/#boardstxt

I guess I'm not making myself clear about what I'm looking for. In other programmers code I've seen statements like the following:

#if defined(AVR_ATmega1280) || defined(AVR_ATmega2560)
^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^

I understand what the statement is about, the programmer is testing to see if either of those two variables have been defined. My question is, "How did the programmer know about those two variables and how they work? And where did he/she find that info?"

Every compiler I have ever worked with (Lattice C, Microsoft Visual Studio C++, Pelles C) provided clear documentation about preprocessor variables and how they are defined, or undefined.

Is there no such documentation for the Arduino compiler? And, if not, why not?

NOTE: There should be doube-underscores infront of and behind each of the variables in the above post. This system is deleting them for some reason, along with the spaces in front of the up-arrows.

It's about to test for which target platform the code is compiled. As @Juraj already stated these definitions depend on the board selected in the IDE and are stored in the corresponding boards.txt files. They are defined in the commandline of the compiler with the -D option. You cannot find them in a .h file.

these are from the AVR toolchain and are based on the -mcu parameter

https://onlinedocs.microchip.com/pr/GUID-317042D4-BCCE-4065-BB05-AC4312DBC2C4-en-US-2/index.html?GUID-830E14F8-A333-4B38-A206-877D7694F324

Probably because yo did not use code tags :wink: If you put it in single backticks or as a code block (triple backticks), it should preserve.

Look at this very similar issue which @in0 answered very comprehensively: Multi-Architecture libraries. Determining target platform or board type

when you specify the board type under Tools, the arduino-builder defines the board type as a compiler option, from which it can determine the processor type

Compiling sketch...
"C:\Tools\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -Wall -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Tools\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Tools\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\lenovo\AppData\Local\Temp\arduino_build_96819\sketch\Tst.ino.cpp" -o "C:\Users\lenovo\AppData\Local\Temp\arduino_build_96819\sketch\Tst.ino.cpp.o"

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.