<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div style="font-size: 13px;">Ugh. I’ve been busy with moving. Apologies for joining late.&nbsp;</div><div style="font-size: 13px;"><br></div><div style="font-size: 13px;">David reported input from Berkeley that the macro-based approach is too complicated, that nested macros will look especially unattractive, and that the pragma syntax isn't much better. Before taking a try-catch solution to the C committee, let’s be sure we’ve really considered the other options. Here’s another look at a pragma approach, because we already have FP pragmas in C and they don’t require language invention ...</div><div style="font-size: 13px;"><br></div><div style="font-size: 13px;">Are pragmas too complicated? In what ways? Are the examples below too simplistic?</div><div style="font-size: 13px;"><br></div><div style="font-size: 13px;">A solution with pragmas (2 of them) would allow code like</div><div style="font-size: 13px;"><br></div><div style="font-size: 13px;">{</div><div style="font-size: 13px;"><span class="Apple-tab-span" style="white-space: pre;">        </span>#pragma FE_EXCEPT FE_OVERFLOW, FE_INVALID</div><div style="font-size: 13px;"><span class="Apple-tab-span" style="white-space: pre;">        </span>/* normal case code */</div><div style="font-size: 13px;"><span class="Apple-tab-span" style="white-space: pre;">        </span>{</div><div style="font-size: 13px;"><span class="Apple-tab-span" style="white-space: pre;">                </span>#pragma FE_HANDLE FE_OVERFLOW</div><div style="font-size: 13px;"><span class="Apple-tab-span" style="white-space: pre;">                </span>/* handle overflow */</div><div style="font-size: 13px;"><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div><div style="font-size: 13px;"><span class="Apple-tab-span" style="white-space: pre;">        </span>{</div><div style="font-size: 13px;"><span class="Apple-tab-span" style="white-space: pre;">                </span>#pragma FE_HANDLE FE_INVALID</div><div style="font-size: 13px;"><span class="Apple-tab-span" style="white-space: pre;">                </span>/* handle invalid */</div><div style="font-size: 13px;"><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div><div style="font-size: 13px;">}</div><div style="font-size: 13px;"></div><div style="font-size: 13px;"><br></div><div style="font-size: 13px;">(The compound statements to handle exceptions could be before the normal case.)&nbsp;</div><div style="font-size: 13px;"><br></div><div style="font-size: 13px;">Why is this particularly more complicated than the try-catch like solutions we’ve been looking at?</div><div style="font-size: 13px;"><br></div><div style="font-size: 13px;">A reference implementation, using existing functions, for the code above could be something like</div><div style="font-size: 13px;"><br></div><div style="font-size: 13px;">{</div><div style="font-size: 13px;"><span class="Apple-tab-span" style="white-space: pre;">        </span>#pragma STDC FENV_ACCESS ON</div><div style="font-size: 13px;"><span class="Apple-tab-span" style="white-space: pre;">        </span>fenv_t fenv;</div><div style="font-size: 13px;"><span class="Apple-tab-span" style="white-space: pre;">        </span>feholdexcept(&amp;fenv);</div><div style="font-size: 13px;"><span class="Apple-tab-span" style="white-space: pre;">        </span>/* normal case code */</div><div style="font-size: 13px;"><span class="Apple-tab-span" style="white-space: pre;">        </span>if (fetestexcept(FE_INVALID) {</div><div style="font-size: 13px;"><span class="Apple-tab-span" style="white-space: pre;">                </span>/* handle invalid */</div><div style="font-size: 13px;"><span class="Apple-tab-span" style="white-space: pre;">                </span>feclearexcept(FE_INVALID);</div><div style="font-size: 13px;"><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div><div style="font-size: 13px;"><span class="Apple-tab-span" style="white-space: pre;">        </span>if (fetestexcept(FE_OVERFLOW) {</div><div style="font-size: 13px;"><span class="Apple-tab-span" style="white-space: pre;">                </span>/* handle overflow */</div><div style="font-size: 13px;"><span class="Apple-tab-span" style="white-space: pre;">                </span>feclearexcept(FE_OVERFLOW);</div><div style="font-size: 13px;"><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div><div style="font-size: 13px;"><span class="Apple-tab-span" style="white-space: pre;">        </span>feupdateenv(&amp;fenv);</div><div style="font-size: 13px;">}</div><div style="font-size: 13px;"><br></div><div style="font-size: 13px;">An ASAP version might be implemented with traps.&nbsp;</div><div style="font-size: 13px;"><br></div><div style="font-size: 13px;">Code using sub exceptions could be</div><div style="font-size: 13px;"><br></div><div style="font-size: 13px;"><div>{</div><div><span class="Apple-tab-span" style="white-space: pre;">        </span>#pragma FE_EXCEPT FE_INVALID_DIVIDE</div><div><span class="Apple-tab-span" style="white-space: pre;">        </span>/* normal case code */</div><div><span class="Apple-tab-span" style="white-space: pre;">        </span>{</div><div><span class="Apple-tab-span" style="white-space: pre;">                </span>#pragma FE_HANDLE FE_INVALID_DIVIDE</div><div><span class="Apple-tab-span" style="white-space: pre;">                </span>/* handle invalid divide */</div><div><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div><div>}</div></div><div style="font-size: 13px;"><br></div><div style="font-size: 13px;">It might have a reference implementation something like</div><div style="font-size: 13px;"><br></div><div style="font-size: 13px;"><div>{</div><div><span class="Apple-tab-span" style="white-space: pre;">        </span>#pragma STDC FENV_ACCESS ON</div><div><span class="Apple-tab-span" style="white-space: pre;">        </span>fenv_t fenv;</div><div><span class="Apple-tab-span" style="white-space: pre;">        </span>feholdexcept(&amp;fenv);</div><div><span class="Apple-tab-span" style="white-space: pre;">        </span>/* normal case code */</div><div><span class="Apple-tab-span" style="white-space: pre;">        </span>if (fetestexcept(FE_INVALID) {</div><div><span class="Apple-tab-span" style="white-space: pre;">                </span>fexcept_t e;</div><div><span class="Apple-tab-span" style="white-space: pre;">                </span>fegetexceptflag(&amp;e, FE_INVALID);</div><div><span class="Apple-tab-span" style="white-space: pre;">                </span>if (_Fetestsubexceptflag(&amp;e, FE_INVALID_DIVIDE) {</div><div><span class="Apple-tab-span" style="white-space: pre;">                        </span>/* handle invalid divide */</div><div><span class="Apple-tab-span" style="white-space: pre;">                </span>}</div><div><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div><div><span class="Apple-tab-span" style="white-space: pre;">        </span>feupdateenv(&amp;fenv);</div><div>}</div></div><div style="font-size: 13px;"><br></div><div style="font-size: 13px;">where (in this possible implementation) the runtime maintains sticky flags for the requested sub exceptions within the relevant exception flag, and the internal function _Fetestsubexceptflag tests an except_t object for sub exceptions.</div><div style="font-size: 13px;"><br></div><div style="font-size: 13px;">-Jim</div><div><br></div><div><div>On Jun 2, 2014, at 4:06 PM, David Hough CFP &lt;<a href="mailto:pcfp@oakapple.net">pcfp@oakapple.net</a>&gt; wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><br><br>Rajan points out that C is really intended to be a one-pass compilable<br>language. &nbsp;&nbsp;&nbsp;Mike points out that there's no necessity for a try block<br>if you can attach exception catches to any syntactic block. &nbsp;&nbsp;&nbsp;So here's<br>a summary of my thinking so far; please respond with your comments:<br><br><br><br>try/catch constructs that differ in some details are found in C++, Java,<br>Perl, PHP, Python, Matlab, and at least two Fortrans for .NET.<br>Ruby has something that is somewhat different<br>syntatically: there is no try keyword; catch clauses (keyword "rescue")<br>can be attached to any compound statement.<br><br>Floating-point exceptions are different from<br>all these other schemes, for which the presence<br>or absence of catch clauses does not affect how the try clause is compiled.<br>However in the case of floating-point exceptions to be detected ASAP<br>by checking operands or flags, then that checking code has to be compiled<br>into the try clause, just for the specific exceptions that the programmer<br>has asked to be detected - one doesn't want to waste time detecting inexact<br>or underflow exceptions unless the programmer asks.<br><blockquote type="cite">From this point<br></blockquote>of view, the common syntactical convention of try followed by catch is<br>a bad choice for one-pass compilers.<br><br>What could be done instead? &nbsp;&nbsp;&nbsp;&nbsp;One could imagine having the catch_excep<br>clauses before the try -<br>and since they are now so syntactically different from C++ etc catch,<br>we might as well leave out the "catch" and just call them "excep":<br><br><br><br>excep () {<br> ... exception code<br>}<br>try {<br> ... try code<br>}<br><br>or perhaps<br><br>try {<br>excep () {<br> ... exception code<br>}<br> ... try code<br>}<br><br><br>And since we're deviating further from C++ syntax anyway, maybe just<br>leave out the explicit try and attach to any compound statement:<br><br>excep() {<br> ... exception code<br>}<br>{<br> ... try code<br>}<br><br>or<br><br>{<br> excep() {<br> ... exception code<br>}<br> ... try code<br>}<br><br>To attain one-pass compilability, one could either require excep clauses to<br>be before the beginning of the compound statement they modify<br>or at the beginning of the compound statement that they modify.<br>I don't know which would be less insulting to C.<br><br>_______________________________________________<br>Cfp-interest mailing list<br><a href="mailto:Cfp-interest@oakapple.net">Cfp-interest@oakapple.net</a><br>http://mailman.oakapple.net/mailman/listinfo/cfp-interest<br></blockquote></div><br></body></html>