Skip to content
View DengY11's full-sized avatar
  • kitty's home

Highlights

  • Pro

Block or report DengY11

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Please don't include any personal information such as legal names or email addresses. Maximum 250 characters, markdown supported. This note will be visible to only you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
DengY11/README.md
#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;
}

Pinned Loading

  1. qax-os/excelize qax-os/excelize Public

    Go language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets

    Go 19.7k 1.8k

  2. redis/go-redis redis/go-redis Public

    Redis Go client

    Go 21.6k 2.5k

  3. redis/redis redis/redis Public

    For 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.

    C 71.1k 24.3k

  4. zeromicro/go-zero zeromicro/go-zero Public

    A cloud-native Go microservices framework with cli tool for productivity.

    Go 31.9k 4.2k

  5. Gecko Gecko Public

    A cpp web framework

    C++ 1

  6. CHIP-8 CHIP-8 Public

    CHIP-8 virtual machine

    C++ 1