Preprocessor Array command creates confusion

I am trying to understand how any pin is set as an output by simple example of blink sketch.
in blink example sketch pinMode function is used as pinMode(LED_BUILTIN,OUTPUT);
further de-coupled pinMode() function i have found" void pinMode(uint8_t pin, uint8_t mode)" again further decoupled "digitalPinToBitMask(pin);" found" #define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )"
then

const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
	_BV(0), /* 0, port D */
	_BV(1),
	_BV(2),
	_BV(3),
	_BV(4),
	_BV(5),
	_BV(6),
	_BV(7),
	_BV(0), /* 8, port B */
	_BV(1),
	_BV(2),
	_BV(3),
	_BV(4),
	_BV(5),
	_BV(0), /* 14, port C */
	_BV(1),
	_BV(2),
	_BV(3),
	_BV(4),
	_BV(5),
};

" my question is "digital_pin_to_bit_mask_PGM[]"is an array of 8 bit unsigned integer type and this array is stored in programe memory . array elements here should be integer type but looking into array all element starts"_BV()" which is not integer . as i have learned c,c++,preprocessor directive i dindnt found this type of array declaration.Please explain how it works like array and data type of array elements are changed?

The _BV() macro is by the gcc compiler for the AVR microcontrollers.
You can find it here: https://www.nongnu.org/avr-libc/user-manual/group__avr__sfr.html
Or you can search your computer for the file "sfr_defs.h".

#define _BV(bit) (1 << (bit))

The macro is for any variable, also for uint8_t.


When the board is not a AVR board, then the _BV() macro might be missing. Arduino has the bit() macro that works for every board: https://www.arduino.cc/reference/en/language/functions/bits-and-bytes/bit/
Sometimes the _BV() macro is added, to be compatible with the AVR chips.

Why do you say so?

Elements are uint8_t in the array. If you provide some other type of integral number in the array initialization then they are silently promoted (truncated) to the destination’s type

Here BV(x), is of type int which will be 2 bytes or 4 bytes depending on your arduino and the promotion takes the LSB so it does what’s expected.

Why is part of the code in italics? Ah, I know, you forgot to use code tags as described in How to get the best out of this forum :smiley:

as i have understood from your reply tha _BV(x) is preprocessor function defined as "#define _BV(bit) (1 << (bit))" here before compiler strats to compile _BV(x ) is replaced by (1<<(x)) and " (1<<(x))" is a integer so array elements type rule not violated.

i am new to this type of forum so i don't know how to push code as example.

Now you can view formated style of code. thanking you for pointing out.

You got it!