C/C++ macro of variable

Dear community.

I am using Arduino library for VGA output. It uses framebuffer - two-dimensional array. Everything works well but the framebuffer has "non-standard" order of the pixels which repeats every 4 bytes. Instead of pixel 1,2,3,4... the framebuffer has order 3,4,1,2...

So instead of this: FrameBuffer[width][height] I have to switch width, height and also xor the width coordinate by 2: FrameBuffer[height][width^2]. It works well, but sometimes I forget about it. It is not standard (standard screen has width and height coordinates).

So my question is: is it possible to write a macro (for example) which will replace (during compilation) the line FrameBuffer[width][height] with FrameBuffer[height][width^2]? Or is there any other way?

Thank you.

Why not just change the line of code to what you need it to be ?

a macro would require parenthesis instead of the square brackets

You could make the FrameBuffer an instance of a custom class and overload the Subscript / array index operator or operator()(int, int) or write a method and instead of FrameBuffer[x][y] you would write FrameBuffer(x,y)

I think I saw it somewhere. Macro which overrides the variable declaration ... or something like that.

Not with square brackets from what I know.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.