#define PIN_USB_HOST_ENABLE (27ul)

Hi I'm new to SAMD21 and looking at variants.h for Sparkfun SAMD21 Dev board. Looking at #define PIN_USB_HOST_ENABLE (27ul). Why is the value inside brackets and what does ul mean? Looking at #define PIN_I2S_SD (9u). What does u mean?


I don't think the brackets are needed in this case; they might be a coding convention in the Sparkfun company.

ul stands for unsigned long; I thought it was actually capitals, but might be wrong. Using UL will tell the compiler to override the default math variable type with the specified type (unsigned long).

Before compiling, there is a pre-compiler step. One of the steps that the pre-compiler does is that when it e.g. encounters PIN_I2S_SD, it will replace it with 9u.

You can get in a lot of trouble if you leave brackets off of function-style macro definitions. In this particular case, there is no need for them but the programmer may have decided it was best practices to just always use brackets. I don't think I'd go so far as to use them in this case but I have come around to just blindly always using them in macro functions because it's easier to do that then waste time thinking about where they're needed and not needed.

ul and UL are equivalent: https://www.arduino.cc/reference/en/language/variables/constants/integerconstants/#_notes_and_warnings