const Array

Hi,
Quick question is it possible to #define an array

Thanks

Yes ... But

(There's a strong whiff of xy here)

what you mean by xy, and how

The XY problem.

Using define.

Okay...
Well
i want to use an array to define pins
currently i just use const int[] definition
which i dont like for pins due to code structure
so i would like to #define an array for pins instead of const int[]

rusus:
currently i just use const int[] definition
which i dont like for pins due to code structure
so i would like to #define an array for pins instead of const int[]

"due to code structure"? Can you be more specific? 'const' is generally considered better for things like this, than #define...

You might be able to answer the question yourself, by considering that a #define is basically just a text replacement (except for macros). You can define an initializer list, like:

#define ledPins {4, A0, 9}

but then what do you do with that? You can't do much but use it to initialize an array:

const uint8_t myLEDPins[] = ledPins;

but what is the point, when you could have just declared the array with the initializer list?

const uint8_t myLEDPins[] = {4, A0, 9};

There are currently no native I/O functions that work with multiple pins, so any solution that you use will involve some kind of array indexing, you can't avoid it. As far as I know, C/C++ can only use lists in limited contexts like initialization, it requires arrays for everything else.

From the Using define page that I linked.

This can have some unwanted side effects though, if for example, a constant name that had been #defined is included in some other constant or variable name. In that case the text would be replaced by the #defined number (or text).
In general, the const keyword is preferred for defining constants and should be used instead of #define.

i just use const int[] definition which i dont like for pins due to code structure

Could you explain what that means?

Got it Thanks Guys