Re: Benign typedef definition
- From: Kaz Kylheku <kkylheku@xxxxxxxxx>
- Date: Thu, 5 Mar 2009 23:38:26 +0000 (UTC)
On 2009-03-05, Keith Thompson <kst-u@xxxxxxx> wrote:
Spiros Bousbouras <spibou@xxxxxxxxx> writes:
[...]
If the objective is to eliminate multiple inclusions of the same[...]
header then a "only once" pragma is a much cleaner solution.
The tricky part would be defining the semantics. Assuming that a
header is a file, consider systems where multiple files can have the
same name (if they're in different directories), and a single file can
have multiple names (links, symbolic links, mount points, etc.).
The simple answer is to use object equality for files rather than name
equality. A file is the same item if it is the same object.
One reasonable assumption is that features of the filesystem structure such as
links, symbolic links and mount points do not change during the compilation of
a program.
In practice, obtaining object quality for files may present problems to
implementors. What if the filesystem doesn't provide any kind of unique ID for
a file? Implementations may have to suffer along with some kind of
weaker equivalence based on names, such as using a canonicalized full path
name (path name to the object, with symlinks substituted for their targets)
or not even that.
This could be left as implementation-defined behavior, and a quality of
implementation issue.
C programs have to be contrived in order for mechanisms like pragma once to
break on name equivalence.
A simple C program that just uses portable header names like "foobar.h"
will not break.
A program which assumes that #include "../foobar.h" in one place the same thing
as #include "abc/foobar.h" is not highly portable; and it is contrived in such
a way as to break simple implementations of pragma once.
I think this is something that the compiler marketplace can sort out for
itself.
.
- Follow-Ups:
- Re: Benign typedef definition
- From: Keith Thompson
- Re: Benign typedef definition
- References:
- Re: Benign typedef definition
- From: Spiros Bousbouras
- Re: Benign typedef definition
- From: Keith Thompson
- Re: Benign typedef definition
- Prev by Date: [OT] Re: Consideration on pointer declarations
- Next by Date: Re: Multiplication or Division of pointer is not supported by C language
- Previous by thread: Re: Benign typedef definition
- Next by thread: Re: Benign typedef definition
- Index(es):
Relevant Pages
|