How to define constant 1 or 2 dimensional array in C/C++? I deal with embedded platform (Xilinx EDK), so the resources are limited.
I'd like to write in third-party header file something like
#define MYCONSTANT 5
but for array. Like
#define MYARRAY(index) { 5, 6, 7, 8 }
What is the most common way to do this?
In C++, the most common way to define a constant array should certainly be to, erm, define a constant array:
const int my_array[] = {5, 6, 7, 8};
Do you have any reason to assume that there would be some problem on that embedded platform?
In C++ source file
extern "C" const int array[] = { 1, 2, 3 };
In header file to be included in both C and C++ source file
#ifdef __cplusplus
extern "C" {
#endif
extern const int array[];
#ifdef __cplusplus
}
#endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With