logoalt Hacker News

jechtoday at 12:45 AM1 replyview on HN

> Give an example of UB code that you have committed in real life

    struct foo {
        ...
        atomic_int v;
        ...
    };
    
    struct foo x;
    memset(&x, 0, sizeof(x));

Replies

rwbttoday at 5:05 AM

I don't think it's UB if you init the struct before using it atomically from multiple threads.