<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span>This is an old topic:<br>
</span>
<div><br>
</div>
<div>http://clang-developers.42468.n3.nabble.com/Warray-bounds-seems-over-zealous-on-Clang-td3162669.html<br>
</div>
<div><br>
</div>
<div>But some points were left not covered.<br>
</div>
<div><br>
</div>
<div>1. "code hygiene" I'd say is that, the code should<br>
</div>
<div>just be portable to "all" compilers, and have the same meaning<br>
</div>
<div>with all of them, with a minimum of ifdefs.<br>
</div>
<div><br>
</div>
<div>2. Furthermore, regarding "same meaning" to all of them,<br>
</div>
<div>there are these choices:<br>
</div>
<div><br>
</div>
<div>typedef struct A1 {<br>
</div>
<div>  int a;<br>
</div>
<div>  int b[0];<br>
</div>
<div>} A1;<br>
</div>
<div><br>
</div>
<div>typedef struct A2 {<br>
</div>
<div>  int a;<br>
</div>
<div>  int b[];<br>
</div>
<div>} A2;<br>
</div>
<div><br>
</div>
<div>typedef struct A3 {<br>
</div>
<div>  int a;<br>
</div>
<div>  int b[1];<br>
</div>
<div>} A3;<br>
</div>
<div><br>
</div>
<div>int a1 = sizeof(A1);<br>
</div>
<div>int a2 = sizeof(A2);<br>
</div>
<div>int a3 = sizeof(A3);<br>
</div>
<div><br>
</div>
<div>They are all valid with clang and probably gcc.<br>
</div>
<div>But they are not likely all valid with additional compilers and through time.<br>
</div>
<div>[1] seems like the most portable and oldest form, and might as well just keep using it indefinitely.</div>
<div><br>
</div>
<div>But it gets a warning.</div>
<div>If one were to ifdef clang to avoid it, one would lose interopation across compilers, as</div>
<div>the various forms do not have the same meaning.</div>
<div>Everyone would have to compile with the same compiler/defines.<br>
</div>
<div>Else the types would vary in size.<br>
</div>
<div><br>
</div>
<div>So I come back to believing that the best choices are either:<br>
</div>
<div> - do not warn for size=1 at end of aggregate<br>
</div>
<div> - possibly a separate setting for specifically that<br>
</div>
<div><br>
</div>
<span>That is what gcc does also it appears (both).</span><br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span><br>
</span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span>I ran across all this exact situation -- ifdef gnuc/clang in some code, with comment that everyone has to compile the same, chosing between 0 and 1 for zero sized array.</span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span>Thank you,</span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span> - Jay</span></div>
</body>
</html>