Found an interesting use of typedef, which I really did not see the need for.
typedef int Color[3];
Thus, the use will be:
Color pants; pants[0] = 0; etc.
Using typedef via ptrs created weird code that was obscure.
Why not just use a struct?
struct Color { int r; int g; int b; }; Color pants; pants.r = 0; etc.
You can use the union to express vars as an array or individually, which is inconvenient, but it is still clear that it is somehow more complex than a single value.
Can anyone give an idea of the virtues of using typedef'd vs. array struct?
, , . , 16 32 . . - ?
- .
int[]
int *
operator=
struct, boost::array .
struct
boost::array
: - , :
void foo (Color c) { size_t s = sizeof(c); }
, c Color * ( ), sizeof(c) sizeof(int*). , , .
Color *
sizeof(c)
sizeof(int*)
: ().
, .
, [rgb], , .
[rgb]
:: ::
, , RGB. , , , pragma pack(), .
pragma pack()
, .x [], operator[] ( ). , static_cast<int*>(this)[index], . , , . - .x() .. [].
operator[]
static_cast<int*>(this)[index]
, , ( Color int*, , int* - , , , IMAO member/free, int *, int , RGB, RGBA, YoCoCg , .
Color
int*
, : valid/sane/debug, .
, , boost:: tuple , .