would be much better, but it does not compile. I tried a lot of types and type castings, no way. Could it be, what I want is completely impossible?
(see MCVE fragment at https://clauduino.de/audioOut2560_6b/index.html)
For some reason, this project cannot be transferred to UNO-R4.
Is it line compiled? I think you have a several problems in it.
It looks like you forget to put the parenthesis around parameter in sizeof operator.
Moreover, the return value of code block { ... } is a result of last operation. So your line abobe is perfectly equivalent just to
adrLen[dest] = sizeof(source) ;
Also It seems to me that the type of the source variable is incorrect. I don't know what the data it is, but it obviously can't be a char. Is it classic string (char array) ?
The parenthesis are not required here. The parenthesis are sometimes necessary, particularly when evaluating the size of a type, such as sizeof (float).
That is not a code block. Unfortunately the OP posted a link to the code instead of putting it in the question, see my previous reply for a modified version of OPs code. adrLen is an array of struct, the line of code is setting the value of an element of the array.
Source is an array of unsigned char (again the OP did not post the code here, only a link).
The source array is an array of unsigned char stored in PROGMEM, and in this case with the possibility of the location in PROGMEM being above the 64K boundary on an atmega2560.
That necessitates the use of the _far version of the PROGMEM functions, such as pgm_read_byte_far().
The type of the pointer is uint_farptr_t, a 24-bit address stored as a uint32_t. The compiler is only able to operate on 16-bit addresses for the atmega2560, necessitating the use of pgm_get_far_address() to produce the pointer at run-time.
Thank you all for your comments.
Yes it is getting complicated.
Initially, I should have made it more clear that the code is compiling, uploading, and working as it should.
So my question was not about accessing data in high memory areas but producing robust code.
That is why I did not waste the forum's precious space by uploading 256 kB of code.
My concern is, it does not look very elegant and above all is less maintainable.
The compiler would still accept a line like this
but one fine day it would give wrong results - and nobody would notice it.
The proposal to use a macro that accepts one parameter and passes it to functions sounds good, but is not easy to define.
I'm not sure what the extra braces were for, though. Maybe you're doing something more complicated. But the pre-processor concatenation operator ("##") looks like it should be your friend.
Thank you for taking the time to help.
Actually, I had to do a small modification as pgm_get_far_address takes only one parameter. Now I am struggeling with
for (int i = 0; i < sounds; i++)
adrLen[i] = loadAdrLen(i);
which does not compile as I keep getting the "lvalue required as unary '&' operand" message, whatever I try the macro expands to "rawDatai" which obviously is not declared.
I keep looking for a really good macro tutorial.
You won't be able to do that. The macro is expanded before the code is compiled, so there is no way to code a variable into the array name.
It might be possible to write a macro that would generate multiple lines of code with incrementing numbers in the variable name, but it is beyond my skills and would be easier done with a text editor.