-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need to specify dependency on unspecified behavior #6
Comments
No its not. To interpret the following: #define f(a) a*g
#define g(a) f(a)
f(2)(9) To expand as See 6.10.3/9:
And 6.10.3/10:
Furthermore, an implementation can't consider possible future invocation by looking ahead for a
DR017 is an old DR that seems to ignore the original intent of the standard text which was derived from Dave Prosser's pseudo-algorithm with the goal of allowing as much expansion as possible while avoiding infinite recursion. The similar C++ DR268 which resulted from a discussion with Dave Prosser shows that it should expand to
Also, with n3882 this behavior could be further clarified in future versions of C++. |
I am not talking about a proposed text for the Standard, but about the text of the Standard. Even if I read the Dave Prosser's pseudo code after I wrote my preprocessor, I already had known of it and its intent. The truth is that the committee decided to endorse an implementation that does not follow the intent by not endorsing code that depends on the unspecified behavior. With the current state of the Standard, nothing prevents an implementation that generates DR017Q19 and other questions and proposals some of which you cited above arise repeatedly because the current interpretation of the Standard allows ambiguity, not because it carries some unintented wording. The authoritative response to DR017Q19 and the informative text added in an annex by C90 COR and kept by the later revisions also agree with that. The fact that some of the committee documents for proposals contain something does not mean they will make their way into the normative text of the Standard. For example, there were several proposals to resolve the trailing comma problem of variadic macros (including gcc's I totally agree that most compilers have no problem with your code, because whatever model a preprocessor hires (iterative one vs. recursive one), forgetting an expansion context as early as possible is easier to implement. There was a comp.std.c discussion where one of former authors of gcc's cpp insisted that the standard preprocessing model is recursive and Doug Gwyn, a member of J11 argued against it. But, as we all know, the cpp from gcc has never stopped at |
I am talking about the text of the standard as well. The purpose of the proposals are only to clarify the current text not to define new behavior.
The committee chose to use a simpler method for the standard text to achieve the same results(ie intent). The original intent is very much relevant when the text becomes unclear.
This is incorrect. The invocation of
I think you have that backwards. Doug Gwyn has argued that the PP model is recursive even though that is not what the current standard specifies nor the original intent(which he was not part of the original implementation). |
If you think the purpose of the proposals is for clarification, then they are actually trying to change the text that the committee intentionally left ambiguous. If you think the committee chose to use a simpler method for delivering the intent (which was described by Dave Prosser's pseudo code), how can we explain the item added in an annex, which allows an implementation to generate
The committee's interpretation and the informative text that must be consistent with the normative part clearly disagree with your interpretation. I am afraid that this kind of discussion is not quite meaningful here because it has been done many times on comp.std.c and, unfortunately I have not enough time for it. If you really think your interpretation is correct, I suggest to start a discussion on comp.std.c.
I should have said IIRC ;-) A recursive approach has no problem (and work better in certain cases) provided that it meets all the requirements of the standard. And Dave Prosser already recognized that the drafted wording for macro rescanning did not completely mimic his algorithm:
And this agrees with Doug Gwyn's recall:
|
It seems they disregarded both the original intent and text of the standard. Perhaps at the time they thought such an implementation could be conforming, but its not. Even decades later there has yet to be a conforming preprocessor to implement it this way.
No, the DR17Q19 merely states that such an implementation could be allowed, however, there no interpretation of the text that could allow such an implementation.
Yes, provided it meets the requirements of the standard, which it cannot. The standard makes it clear that replacement must happen separately before rescanning. So recursively applying replacements and then rescanning is non-conforming. |
The goal of the C90 Committee to write wording for preprocessing was not to move Dave's algorithm into plain English without any change. So, I think we need to separate the Committee's intent from Dave Prosser's code and to stop calling the code as the original intent, because we have:
I carefully avoid saying that the Standard's wording should be read as to accommodate implementation choices because I think that is the point where we disagree.
Your point seems that the literal reading of the Standard is not to allow conforming preprocessors to keep the blue-painted set when bringing an open parenthesis beyond some boundaries. I could argue that a reading of text gives a different interpretation, but, again I think this, a github issue page is not a proper place to discuss it. I learned from my experiences on comp.std.c that this kind of discussions takes much time to figure out each others' understanding and misunderstanding, which is why I suggest to open a new discussion on the newsgroup to see how others read the text. The text of the Standard is written to deliver the intent of the Committee and a DR should be filed when it fails. You insist that the text in question doesn't allow implementation choices when handling blue-painted tokens, which implies a DR to change the text or their intent should be in order, and as a practical user (as opposed to a theoretical one) of the Standard, I think taking the intent behind the wording (as opposed to taking its literal reading) is a proper approach until the DR gets a proper response. Your ideas for implementing detection and iteration with preprocessing features are interesting, and I don't think adding a note about the Committee's intent for the behavior on which your code depends reduces fun of reading the code. Or you are free to leave it as unspecified, as the Committee does, if you don't care whether or not people ignorant of this story mistake it is unarguably safe to depend on the behavior in their code. |
It seems to necessary to specify that the code to enable recursive macro expansion is not conforming to the C Standard.
FOREVER_INDIRECT
in the wiki page is defined not to have in it parentheses to invokeFOREVER
because that would stop further expansion ofFOREVER_INDIRECT
. This is, however, is an unspecified behavior and a standard-conforming compiler is free to stop the expansion; refer to DR017Q19 for details.The reason that most compilers drop the
FOREVER_INDIRECT
's context when brining parentheses from the outside of its replacement list is that doing so is easier than to keep it.I think this should be described in the wiki page.
Thanks.
The text was updated successfully, but these errors were encountered: