3 ms·
I've come across obscure bugs with header guards in open source software that went unnoticed for years -- essentially, there were competing definitions of a glo
by jstimpfle 2y ago
I've come across obscure bugs with header guards in open source software that went unnoticed for years -- essentially, there were competing definitions of a global config struct in the code base. Some parts of the code would access Version A, while others would access the same data but thinking it was version B.
Most .c files had ended up including both versions, but the headers had the same guards so only the first included definition would be in effect.
The project maintainer had been fixing obscure memory bugs for years until someone noticed the real issue.
Wouldn't have happened with #pragma once I suppose. With pragma once you don't have to painfully choose an identifier for the header guard, and you can't get that wrong.
- uecker 2y agoPragma once itself gets it wrong, if there are multiple paths to the same file which apparently happens quite a lot.
- jstimpfle 2y agoNever seen it happen. Seems like myth, who uses hardlinks/symlinks in source projects? And is pragma once not implemented based on inpdes? Anyway false negative identity tests is not a problem like false positive identity tests are.
- deleted 2y ago[deleted]