91 lines
1.9 KiB
C++
91 lines
1.9 KiB
C++
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
#define CALLBACK(init,end) \
|
|
{ \
|
|
.init_cena = init, \
|
|
.end_cena = end \
|
|
}
|
|
|
|
#define ATTRIBUTE_NO_RETURN __attribute__((__noreturn__))
|
|
|
|
#define CALLBACK_ARRAY_SIZE(array) sizeof(array)/sizeof(Callback)
|
|
|
|
typedef struct Callback {
|
|
void (*init_cena)(void);
|
|
void (*end_cena)(void);
|
|
} Callback;
|
|
|
|
void end_cena_cool(){
|
|
std::cout << "End cool stuff" << std::endl;
|
|
}
|
|
|
|
void end_cena_not_cool(){
|
|
std::cout << "End not cool stuff" << std::endl;
|
|
}
|
|
|
|
void init_cena_cool(){
|
|
std::cout<< "Init cool stuff" << std::endl;
|
|
}
|
|
|
|
void init_cena_not_cool(){
|
|
std::cout << "Init not cool stuff" << std::endl;
|
|
}
|
|
|
|
void void_func(){
|
|
std::cout << "Void function 1" << std::endl;
|
|
}
|
|
|
|
void void_func2() ATTRIBUTE_NO_RETURN;
|
|
|
|
void void_func2(){
|
|
exit(0);
|
|
}
|
|
|
|
#define COLOR_ARRAY 3
|
|
|
|
typedef union Color{
|
|
struct {
|
|
int r;
|
|
int g;
|
|
int b;
|
|
};
|
|
int color_array[COLOR_ARRAY];
|
|
} Color;
|
|
|
|
int main(int argc, char** argv){
|
|
Callback calls[]={
|
|
CALLBACK(init_cena_cool, end_cena_cool),
|
|
CALLBACK(init_cena_not_cool,end_cena_not_cool),
|
|
CALLBACK(init_cena_cool, end_cena_not_cool),
|
|
CALLBACK(init_cena_not_cool, end_cena_cool)
|
|
};
|
|
|
|
|
|
Callback empty_calls[]={};
|
|
|
|
std::cout << "Hello cenas" << std::endl;
|
|
|
|
std::cout << "Size of Callback entry bytes:" << sizeof(calls[0]) << std::endl;
|
|
std::cout << "Size of Callback array bytes: " << sizeof(calls) << std::endl;
|
|
std::cout << "Number of Callback entries: " << sizeof(calls)/sizeof(Callback) << std::endl;
|
|
std::cout << "Empty calls size: "<< CALLBACK_ARRAY_SIZE(empty_calls) << std::endl;
|
|
|
|
int array_size = CALLBACK_ARRAY_SIZE(calls);
|
|
int i=0;
|
|
for(i=0;i<array_size;i++){
|
|
calls[i].init_cena();
|
|
calls[i].end_cena();
|
|
}
|
|
|
|
Color color;
|
|
|
|
color.color_array[0]=10;
|
|
color.color_array[1]=20;
|
|
color.color_array[2]=30;
|
|
std::cout << "R: " << color.r << " G: " << color.g << " B: " << color.b << std::endl;
|
|
std::cout << sizeof(color) << std::endl;
|
|
}
|
|
|
|
|