<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Sep 21, 2016 at 10:06 PM, Fred J. Tydeman via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">There are some problems with the C preprocessor definition in the C standard.<br>
Following is a proposal to fix one area of those problems.<br>
Does this seem like a good idea? Any suggestions on this proposal?<br>
Any chance that clang would implement this before it becomes part of the C<br>
standard (so that the C committee has feedback on how good/bad this idea is)?<br></blockquote><div><br></div><div>It's not obvious to me how this differs from our current behavior, other than the new "#line __LINE__" syntax. Can you suggest cases that would change behavior for us with this proposal?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><br>
<br>
<html><br>
<head><br>
<meta name="generator" content=<br>
"HTML Tidy for OS/2 (vers 1 September 2005), see <a href="http://www.w3.org" rel="noreferrer" target="_blank">www.w3.org</a>"><br>
<br>
<title>N21xx C2X Proposal: Preprocessor line numbers</title><br>
</head><br>
<br>
<body><br>
<p><br><br>
<!-- Who are the authors... --><br>
<b>Submitter:</b>Fred J. Tydeman<br><br>
<!-- What is the date of submission. yyyy-mm-dd --><br>
<b>Submission Date:</b>2016-09-??<br><br>
<b>Document:</b> WG14 N21xx<br></p><br>
<br>
<p>Problem being solved</p><br>
<br>
<p>With respect to preprocessor behaviour of line numbers and<br>
__LINE__, there are differences between implementations, and<br>
between releases of the same implementations.</p><br>
<br>
<p>For most implementations, it is not clear what conventions are<br>
being used for line numbering, therefore, one cannot predict what<br>
line number will be associated with a given preprocessor<br>
token.</p><br>
<br>
<p>This makes if very difficult to write portable code that has<br>
consistent behaviour.</p><br>
<br>
<p>This has shown up in (at least) DRs 173, 464, 483.</p><br>
<br>
<p>Solution</p><br>
<br>
<p>Add the following to 6.10.4 Line control:</p><br>
<br>
<blockquote><br>
<p>The presumed line number (footnote 1) associated with a<br>
preprocessor token shall be the presumed line number of the<br>
first character of the preprocessor token, except for the<br>
preprocessor tokens in a macro replacement-list which get the<br>
presumed line number of the macro invocation (footnote 2).</p><br>
<br>
<p>(footnote 1) The presumed line number is the same as the<br>
physical line number unless changed by a #line directive.</p><br>
<br>
<p>(footnote 2) Required by the assert() macro.</p><br>
<br>
<p>The presumed line number associated with a macro invocation<br>
shall be the presumed line number of the macro name of the<br>
invocation.</p><br>
<br>
<p>The presumed line number of a preprocessing directive shall<br>
be the presumed line number of the # preceding the directive<br>
name.</p><br></blockquote><div><br></div><div>What does this affect?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<p>A preprocessing directive of the form<br><br>
<code>#line __LINE__ "filename"</code><br><br>
shall change the presumed file name without changing the<br>
presumed line number.</p><br></blockquote><div><br></div><div>Why is this useful?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote><br>
<br>
<p>Existing practice</p><br>
<br>
<p>Based upon my testing, each of the above requirements has been<br>
implemented by at least one implementation, however, it is not<br>
clear if there are any implementations that do them all.</p><br>
</body><br>
</html><br>
<br>
<br>
---<br>
Fred J. Tydeman Tydeman Consulting<br>
<a href="mailto:tydeman@tybor.com">tydeman@tybor.com</a> Testing, numerics, programming<br>
<a href="tel:%2B1%20%28775%29%20287-5904" value="+17752875904">+1 (775) 287-5904</a> Vice-chair of PL22.11 (ANSI "C")<br>
Sample C99+FPCE tests: <a href="http://www.tybor.com" rel="noreferrer" target="_blank">http://www.tybor.com</a><br>
Savers sleep well, investors eat well, spenders work forever.<br>
______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div></div>