|
|
|
|
|
by kazinator
2760 days ago
|
|
> It doesn't need to be robust against byzantine source trees A locally developed hack, or even a compiler extension, doesn't have to be; an ISO-standard feature should be well specified. If something is specified in such a way that it is less robust than the #ifndef trick, then any programmer worth their salt will use the #ifndef trick. An acceptable pragma-once would look like this: #pragma once 9DF9-C3D9-BDF0
Basically it should take an argument string which specifies an ID for the file, intended to be unique. |
|
That claim doesn't match up with the C standard I've read. I.e., this is an "isolated demand for rigor." Are we looking at the same document? Quite a lot is underspecified or implementation defined to accommodate differences in architectures and systems.
The 2018 C standard doesn't specify whether NULL is a pointer or integer; what a null pointer's representation is; nor the representation of negative (signed) integers. The C standard defines some loose requirements around observable behavior and leaves the specific details to the implementation.
> Basically it should take an argument string which specifies an ID for the file, intended to be unique.
Or the standard could leave it up to the implementation to identify file uniqueness without this additional, incompatible argument. Like I said before, all you have to do for Unix implementations to be as robust as the stupid ifndef trick is to check st_ino and st_dev.
It's important to recognize that implementations and implementation details are distinct from the standard.
Also note that the ifndef hack is non-robust in its own way — false positive exclusions due to accidental identifier conflicts. #pragma once does not have this problem.