<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>At least with the clang implementation of _Generic, this fell over with several errors. I was able to <i>mostly</i> patch it up like so:</div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; min-height: 13px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(119, 73, 46); ">#define totalorder(x,y) \</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(119, 73, 46); "> _Generic((x), float: _Generic((y), \</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(119, 73, 46); "> float: totalorderf, \</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(119, 73, 46); "> double: _Static_assert(<span style="color: #351ed3">0</span>, <span style="color: #cf2a24">"type mismatch"</span>)), \</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(119, 73, 46); "> double: _Generic((y), \</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(119, 73, 46); "> float: _Static_assert(<span class="Apple-style-span" style="color: rgb(119, 73, 46); font-family: Menlo; font-size: 11px; "><span style="color: rgb(53, 30, 211); ">0</span></span><span class="Apple-style-span" style="color: rgb(119, 73, 46); font-family: Menlo; font-size: 11px; ">, </span><span class="Apple-style-span" style="color: rgb(119, 73, 46); font-family: Menlo; font-size: 11px; "><span style="color: rgb(207, 42, 36); ">"type mismatch"</span></span><span class="Apple-style-span" style="color: rgb(119, 73, 46); font-family: Menlo; font-size: 11px; ">)), \</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(119, 73, 46); "> double: totalorder))((x),(y))</div></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(119, 73, 46); "> </div><div>but it still fails for exactly the reason that Joel highlighted; _Generics expand to expressions, which _Static_assert is not. I don't see any straightforward way around this, unfortunately. One could replace the _Static_assert with a function that causes a runtime failure, but that's not at all satisfactory.</div><div><br></div><div>- Steve</div><br><div><div>On Jul 14, 2011, at 4:01 PM, Joel C. Salomon wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Folks,<br><br>Here's what I had in mind for using C1x's _Generic to catch invalid uses<br>of totalorder(x,y):<br><br>int totalorder(double x, double y);<br>int totalorderf(float x, float y);<br><br>#define totalorder(x, y) _Generic((x), \<br><span class="Apple-tab-span" style="white-space:pre">        </span>float: _Generic((y), \<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>float: totalorderf((x), (y)) \<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>) \<br><span class="Apple-tab-span" style="white-space:pre">        </span>double: _Generic((y), \<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>float: _Static_assert(0, "type mismatch"), \<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>double: totalorder((x), (y)) \<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>) \<br><span class="Apple-tab-span" style="white-space:pre">        </span>)<br><br>(I'm not actually sure the _Static_assert is completely correct; N1570<br>§6.7.10 implies that static assertions need to be statements, not<br>expressions, so a line like<br><br><span class="Apple-tab-span" style="white-space:pre">        </span>int i = totalorder(1.0, 2.0f) + 17;<br><br>may give the wrong compile error.)<br><br>Does this seem a reasonable path to continue down?<br><br>--Joel Salomon<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></div></blockquote></div><br></body></html>