11.0 Výčtové typy Výčtové typy jsou jakoby sdružená makra. Prostě uděláte množinu konstant, které dáte datový typ. (ve skutečnosti to bude integer, což přináší dost výhod pro operace s výčtovými typami :-)) Definují se takto :
typedef enum { ZLUTA, MODRA, ZELENA, RUZOVA } BARVY; |
enum eLumps { kEntities = 0, kTextures, kPlanes, kNodes, kLeafs, kLeafFaces, kLeafBrushes, kModels, kBrushes, kBrushSides, kVertices, kMeshVerts, kShaders, kFaces, kLightmaps, kLightVolumes, kVisData, kMaxLumps }; |
enum Barvy { Zluta = 0xffff00, Modra = 0x0000ff, Zelena = 0x00ff00, Ruzova = 0xff00ff }; |
enum Barvy { Zluta = 5, Modra = 1, Zelena = 3, Ruzova }; |
Barvy b; b = Zluta; |
typedef int POLE[10]; |
POLE i; |
int i[10]; |
typedef unsigned int uint; typedef unsigned long ulong; |
typedef struct { float x, y, z; } Vector; |
struct Vector3f { float x, y, z; }; |
struct Zamestnanec { int vek, vaha; float vyska; long plat; }; |
Zamestnanec z, u; z.vek = 58; z.vaha = 100; z.vyska = 1.82; z.plat = 10000; u = z; |
Zamestnanec *z; z = (Zamestnanec*) malloc(sizeof(Zamestnanec)); z->vek = 58; z->vaha = 100; z->vyska = 1.82; z->plat = 10000; |
struct Mnohouhelnik { int x, y; struct Mnohouhelnik *next; // Ukazatel na další bod // Nesmí být Mnohouhelnik next; }; |
/* PC_Gamer.cpp */ #include |
struct Seznam { // nejaky data . . // nejaky data struct Seznam *dalsi, *predchozi; // ukazatel na sousedni prvky }; |
struct bitove_pole { unsigned neco : 8; // 00000000 ???????? unsigned neco_jineho : 3; // 00000??? 00000000 unsigned flag : 1; // 0000?000 00000000 unsigned cislo : 3; // 0???0000 00000000 unsigned priznak : 1; // ?0000000 00000000 }; |
struct datum { unsigned den : 5; // 00000000 000????? unsigned mesic : 4; // 0000000? ???00000 unsigned rok : 7; // ???????0 00000000 }; |
struct pokus { char a; short b; short c; }; |
struct Zamestnanec { int vek, vaha; float vyska; long plat; } *z; |
struct { int vek, vaha; float vyska; long plat; } z; |
struct { int vek, vaha; float vyska; long plat; } z[] = { {23, 96, 123.5, 20000}, {25, 66, 72, 25000}, {43, 43, 107.2, 12500}, {82, 158, 56, 10000} }; |
union Muj_Union { char m_char; int m_int; long m_long; float m_float; double m_double; }; |
struct DWORDREGS { unsigned long edi; unsigned long esi; unsigned long ebp; unsigned long cflag; unsigned long ebx; unsigned long edx; unsigned long ecx; unsigned long eax; unsigned short eflags; }; struct DWORDREGS_W { unsigned long di; unsigned long si; unsigned long bp; unsigned long cflag; unsigned long bx; unsigned long dx; unsigned long cx; unsigned long ax; unsigned short flags; }; struct WORDREGS { unsigned short di, _upper_di; unsigned short si, _upper_si; unsigned short bp, _upper_bp; unsigned short cflag, _upper_cflag; unsigned short bx, _upper_bx; unsigned short dx, _upper_dx; unsigned short cx, _upper_cx; unsigned short ax, _upper_ax; unsigned short flags; }; struct BYTEREGS { unsigned short di, _upper_di; unsigned short si, _upper_si; unsigned short bp, _upper_bp; unsigned long cflag; unsigned char bl; unsigned char bh; unsigned short _upper_bx; unsigned char dl; unsigned char dh; unsigned short _upper_dx; unsigned char cl; unsigned char ch; unsigned short _upper_cx; unsigned char al; unsigned char ah; unsigned short _upper_ax; unsigned short flags; }; union REGS { /* Compatible with DPMI structure, except cflag */ struct DWORDREGS d; #ifdef _NAIVE_DOS_REGS struct WORDREGS x; #else #ifdef _BORLAND_DOS_REGS struct DWORDREGS x; #else struct DWORDREGS_W x; #endif #endif struct WORDREGS w; struct BYTEREGS h; }; |