-4

I not understand what's mean unsigned char field[1];

#define FLGX (224)  

struct game {
    unsigned char field_width;
    unsigned char field_height;
    unsigned char field[1]; 
};                       
  
#define GETPOS(g,x,y) (g->field[(g->field_width + 2) * ((y)+1) + ((x)+1)] & (0xff ^ FLGX))
GSerg
  • 76,472
  • 17
  • 159
  • 346
  • The answer depends on whether you are converting to have it in C# only or to [marshal it to C++](https://stackoverflow.com/q/5902103/11683) afterwards. – GSerg Aug 30 '23 at 09:43
  • 1
    Looks like a placeholder field used for casting a block of memory that has a much longer `field`: https://stackoverflow.com/questions/14643406/whats-the-need-of-array-with-zero-elements – Matthew Watson Aug 30 '23 at 09:50
  • Offtopic: this macro looks bad - since it can be easily replaced by function or function template. Additionally it looks like some hack for variable length 2d array, which is in this form definitely UB. See [this cppcon](https://youtu.be/IAdLwUXRUvg?si=yGunVgJuAMM6jhvP&t=884). – Marek R Aug 30 '23 at 11:18

1 Answers1

0

Trying to translate languages line by line is a bad idea. Conceptually this struct just holds a width and height along with a char array of size width * height. The GETPOS macro indexes into that char array and masks off some bits used for bookkeeping. In C# you can just have a char[].

Botje
  • 26,269
  • 3
  • 31
  • 41