|
|
|
|
|
by tpolzer
2761 days ago
|
|
You could say that there's no reason we're still using a stupid preprocessor hack of textual inclusion to import interfaces. As usual, the devil lies in the detail. If you want to make pragma once robust you need to checksum files, which in the end will be slower than include guards. |
|
#pragma once can be defined in terms of a reference model whereby it is equivalent to a machine-generated sequence:
where the detailed semantics is tied to how the machine generates <ident>.If <ident> is a digest of the absolute path, then references to the same file via different hard or symbolic links look different and do not mutually exclude.
If <ident> is produced from the volume and object identifier (like inode number) then different links to the same header will mutually exclude.
If <ident> is a content hash, then identical files will mutually exclude (but we need to deal with hash collisions somehow).
A much better solution would be to sidestep this whole thing entirely and just allow any file-scope definition in C++ to be repeated in the same translation unit (with some proviso, like that the multiple definitions have to be identical; and that could be enforced with diagnostics). The multiple inclusions of the same material aren't a problem.