#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#define TECH_LIST \
X("System Principles") \
X("Infrastructure") \
X("Low-level C/C++")\
X("Backend dev golang")
#define HOBBY_LIST \
X("Running ") \
X("Guitar ") \
X("Animals ") \
X("Photography ")
typedef struct {
const char *target;
} Dream;
typedef struct {
const char *job;
const char *task;
} Reality;
typedef struct {
const char **tech;
size_t tech_count;
const char **life;
size_t life_count;
} Interest;
typedef struct Me Me;
struct Me {
Dream dream;
Reality reality;
Interest interest;
const char *(*whoami)(Me *self);
void (*show)(Me *self);
const char *(*pursuit)(Me *self);
};
#define NEW(type, ...) ((type*)memcpy(malloc(sizeof(type)), &(type)__VA_ARGS__, sizeof(type)))
#define ARRAY(...) (const char*[]){__VA_ARGS__}, sizeof((const char*[]){__VA_ARGS__})/sizeof(char*)
const char *whoami_impl(Me *self) {
(void)self;
return "A backend developer who dreams of being a geek.";
}
void show_impl(Me *self) {
printf("hi %s\n\n", self->whoami(self));
printf("== Reality ==\nJob: %s\nTask: %s\n\n", self->reality.job, self->reality.task);
printf("== Dream ==\n%s\n\n", self->dream.target);
printf("== Tech Interests ==\n");
for (size_t i = 0; i < self->interest.tech_count; i++) {
printf(" - %s\n", self->interest.tech[i]);
}
printf("\n== Life Hobbies ==\n");
for (size_t i = 0; i < self->interest.life_count; i++) {
printf(" - %s\n", self->interest.life[i]);
}
}
const char *pursuit_impl(Me *self) {
return self->dream.target && strlen(self->dream.target)
? self->dream.target
: self->reality.task;
}
Me *new_me() {
const char *tech[] = {
#define X(item) item,
TECH_LIST
#undef X
};
const char *hobbies[] = {
#define X(item) item,
HOBBY_LIST
#undef X
};
return NEW(Me, {
.dream = {"Contribute to Redis & Linux Kernel"},
.reality = {"Backend Engineer", "Write business code"},
.interest = {ARRAY(tech[0], tech[1], tech[2]),
ARRAY(hobbies[0], hobbies[1], hobbies[2], hobbies[3])},
.whoami = whoami_impl,
.show = show_impl,
.pursuit = pursuit_impl
});
}
int main() {
Me *me = new_me();
me->show(me);
printf("\n Pursuing: %s\n", me->pursuit(me));
__asm__ volatile ("nop");
free(me);
return 0;
}
Highlights
- Pro
Pinned Loading
-
qax-os/excelize
qax-os/excelize PublicGo language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets
-
-
redis/redis
redis/redis PublicFor developers, who are building real-time data-driven applications, Redis is the preferred, fastest, and most feature-rich cache, data structure server, and document and vector query engine.
-
zeromicro/go-zero
zeromicro/go-zero PublicA cloud-native Go microservices framework with cli tool for productivity.
Something went wrong, please refresh the page to try again.
If the problem persists, check the GitHub status page or contact support.
If the problem persists, check the GitHub status page or contact support.