GithubHelp home page GithubHelp logo

Hi, I'm Luigi

linkedin | website | email


Full time:

  • 🏫 SWE at McMaster University
  • πŸ’Ό Intern at Intel

Free time:

  • πŸ‘¨β€πŸ’» Von Neumann Enjoyer
  • 🐧 FOSS Enthusiast

Interesting snippets

Stack UB (-O0)

void A() { int x = 42; }
int B() { int x; return x; }

int main() {
    A();
    printf("%d\n", B());
}

Register UB (-O0)

void A(int x) {}
int B() { int x; return x; }

int main() {
    A(42);
    printf("%d\n", B());
}

Computed GOTO

void jump(void* p) { goto* p; }

int main() {
    void* p = &&foo;
    jump(p);

    printf("A\n");
foo:
    printf("B\n");
}

Faster switch

#include <cstdio>
#include <cstdint>

enum Instruction : uint8_t { Done, A, B, C };

void execute(const Instruction* list) {
    constexpr void* labels[] = {
        [Instruction::Done] = &&Done,
        [Instruction::A] = &&A,
        [Instruction::B] = &&B,
        [Instruction::C] = &&C,
    };
    const auto next = [&] { return labels[*list++]; };
    goto* next();

Done: return;
A:  printf("A\n"); goto* next();
B:  printf("B\n"); goto* next();
C:  printf("C\n"); goto* next();
}

int main() {
    constexpr Instruction list[] = {C, B, A, Done};
    execute(list);
}

Duff's device

#include <stddef.h>
#include <stdio.h>

void better_memcpy(void* restrict dest, void* restrict src, size_t n) {
    unsigned char* to = dest;
    unsigned char* from = src;
    int remain = (n + 7) / 8;
    switch (n % 8) {
        case 0: do { *to++ = *from++;
        case 7:      *to++ = *from++;
        case 6:      *to++ = *from++;
        case 5:      *to++ = *from++;
        case 4:      *to++ = *from++;
        case 3:      *to++ = *from++;
        case 2:      *to++ = *from++;
        case 1:      *to++ = *from++;
        } while (--remain > 0);
    }
}

int main() {
    int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
    int b[sizeof(a) / sizeof(a[0])];
    better_memcpy(b, a, sizeof(b));
    printf("%d\n", b[8]);
}

Hello, World!

#define print(...) puts(#__VA_ARGS__)
int main() { print(Hello, World!); }
int main() {
    __uint128_t x = ((__uint128_t)0x290E4D9CB7 << 64) | 0xD740B37ECD996400;
    while (x >>= 7) putchar(x & 0x7F);
}

Luigi Quattrociocchi's Projects

Luigi Quattrociocchi doesn’t have any public repositories yet.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.