Re:Clang is better than GCC
by Stratoscope on Sunday November 27, 2022 @09:29PM
(#33769196)
When I used to write a lot of C code, my solution for this was to avoid calling memcmp() directly at all when I only cared about a yes/no on the match. Instead I used a wrapper I called memeq():
Re:Clang is better than GCC
by jcelerier on Monday November 28, 2022 @09:04AM
(#33773747)
Reading this makes me appreciate how nice it is in c++ to just be able to do operator==() = default; to let the compiler generate the appropriate comparator automatically
I would also use a typedef for the struct, so you don't have to keep writing "struct" everywhere:
With those two tricks, the erroneous memcmp() call becomes: You're a lot less likely to get that wrong!