I created a class that looks like an array, but instead of storing data in the program itself, it transfers a byte from the file (to reduce the impact of RAM). Now it all works for me, but the programmer must define the class using the following:
#define CreateReadOnlyBlock(name, location, size, ...) \
template<> \
const unsigned int ReadOnlyBlock<location, size>::Data[] \
__asm__( ".readonly__" #location "__" #name) \
= { __VA_ARGS__ }; \
ReadOnlyBlock<location, size> name;
Example:
CreateReadOnlyBlock(readOnlyArray, 0, 4, 0, 1, 2, 3);
Note that this is for the embedded processor, and the asm directive goes through an assembler tool to create a read-only file.
So here is my question: how can I eliminate the variables "location" and "size"? I hate that the programmer has to enter them manually, and he prefers some way of generating data at compile time. Therefore, instead of the programmer who needs to enter:
CreateReadOnlyBlock(readOnlyArray1, 0, 4, 0, 1, 2, 3);
CreateReadOnlyBlock(readOnlyArray2, 4, 4, 4, 5, 6, 7);
They could simply enter:
CreateReadOnlyBlock(readOnlyArray1, 0, 1, 2, 3);
CreateReadOnlyBlock(readOnlyArray2, 4, 5, 6, 7);
. . ++ 11 - , (- constexpr ?). , C-Preprocessor , , . ?
EDIT :
ReadOnlyBlock :
template<const int _location, const int _size> class ReadOnlyBlock
{
...
unsigned int operator[] (size_t index)
{
return LoadFromROM(index + _location);
}
}
ROM, , . , , , ++, .
EDIT:
1 k , . , !