pokitto / PokittoLib

Library for making programs on Pokitto hardware
22 stars 16 forks source link

Find alternative to zero-size arrays. #70

Closed Pharap closed 4 years ago

Pharap commented 5 years ago

The C++ language does not permit arrays of size zero. The library currently contains several conditionally-compiled zero-size arrays that ought to be replaced or removed.

https://github.com/pokitto/PokittoLib/blob/f868d13acd2332884e915eeb7f5fc85742592ff6/Pokitto/POKITTO_CORE/PokittoDisplay.cpp#L187

https://github.com/pokitto/PokittoLib/blob/f868d13acd2332884e915eeb7f5fc85742592ff6/Pokitto/POKITTO_CORE/PokittoDisplay.cpp#L191

HomineLudens commented 5 years ago

Is this just for tiled mode? And what the difference in this if statement?

#if (POK_SCREENMODE == MODE_TILED_1BIT)
    uint8_t Display::width = POK_LCD_W;
    uint8_t Display::height = POK_LCD_H;
    uint8_t Display::screenbuffer[0];
#else
    uint8_t Display::width = POK_LCD_W;
    uint8_t Display::height = POK_LCD_H;
    uint8_t Display::screenbuffer[0];
#endif

What about this? https://github.com/pokitto/PokittoLib/blob/f868d13acd2332884e915eeb7f5fc85742592ff6/Pokitto/POKITTO_CORE/PokittoDisplay.cpp#L181

Can we put to screenbuffer[1]?

Why this? https://github.com/pokitto/PokittoLib/blob/f868d13acd2332884e915eeb7f5fc85742592ff6/Pokitto/POKITTO_CORE/PokittoDisplay.cpp#L177

and not? uint8_t __attribute__ ((aligned)) Display::screenbuffer[220*176];

Pharap commented 5 years ago

Is this just for tiled mode?

As far as I can tell, yes. But that's irrelevant. Whatever mode it's for, zero-sized arrays are non-standard.

A compiler that obeys the rules of standard C++ is required to report an error upon encountering a zero-sized array. Zero-sized arrays are only permitted by non-standard language extensions.

What about this?

That's a different issue.

Why this?

A good point, the hexadecimal is cryptic here, but it should be ((220 * 176) / 2), but again, it's not relevant to the zero-sized array issue.

HomineLudens commented 5 years ago

That's a different issue.

I think it's related, if we opt for a solution to zero-sized array, it should be applied also to this (if the comment is true).

Pharap commented 4 years ago

Fixed by 24d7ed8. (Specifically here.)