108 lines
2.7 KiB
C++
108 lines
2.7 KiB
C++
#include "../src/platform/dsl/pt.h"
|
|
#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
|
|
|
|
enum Colors { RED, GREEN, BLUE };
|
|
|
|
typedef union Color {
|
|
struct {
|
|
int r;
|
|
int g;
|
|
int b;
|
|
};
|
|
int color_array[COLOR_ARRAY];
|
|
} Color;
|
|
|
|
void printColor(const Color &color) {
|
|
std::cout << "[" << color.r << "," << color.g << "," << color.b << "]"
|
|
<< std::endl;
|
|
}
|
|
|
|
Color red = {{
|
|
.r = 1,
|
|
.g = 0,
|
|
.b = 0,
|
|
}};
|
|
Color green = {{
|
|
.r = 0,
|
|
.g = 1,
|
|
.b = 0,
|
|
}};
|
|
Color blue = {{
|
|
.r = 0,
|
|
.g = 0,
|
|
.b = 1,
|
|
}};
|
|
|
|
Color colors[] = {[RED] = red, [GREEN] = green, [BLUE] = blue};
|
|
|
|
int main(int argc, char **argv) {
|
|
Callback callbacks[] = {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_callbacks[] = {};
|
|
|
|
std::cout << "Hello cenas" << std::endl;
|
|
|
|
std::cout << "Size of Callback entry bytes:" << sizeof(callbacks[0])
|
|
<< std::endl;
|
|
std::cout << "Size of Callback array bytes: " << sizeof(callbacks)
|
|
<< std::endl;
|
|
std::cout << "Number of Callback entries: "
|
|
<< sizeof(callbacks) / sizeof(Callback) << std::endl;
|
|
std::cout << "Empty callbacks size: " << CALLBACK_ARRAY_SIZE(empty_callbacks)
|
|
<< std::endl;
|
|
|
|
int array_size = CALLBACK_ARRAY_SIZE(callbacks);
|
|
int i = 0;
|
|
for (i = 0; i < array_size; i++) {
|
|
callbacks[i].init_cena();
|
|
callbacks[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;
|
|
se(0 == 0) { std::cout << "SIm" << std::endl; }
|
|
senao {}
|
|
|
|
printColor(colors[RED]);
|
|
printColor(colors[GREEN]);
|
|
printColor(colors[BLUE]);
|
|
}
|