<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jan 29, 2021 at 11:38 AM Joel Sherrill <<a href="mailto:joel.sherrill@gmail.com">joel.sherrill@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jan 29, 2021, 12:28 PM Sebastian Huber <<a href="mailto:sebastian.huber@embedded-brains.de" target="_blank">sebastian.huber@embedded-brains.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 29/01/2021 18:33, Peter Dufault wrote:<br>
<br>
>>> Do not use an enum as a bit field. Document the state flags.<br>
>>><br>
>>><br>
>>> Is this a new style rule that needs to be documented?<br>
>> Into which category would you put this? Language and Compiler?<br>
>><br>
>> <a href="https://docs.rtems.org/branches/master/eng/coding-conventions.html" rel="noreferrer noreferrer" target="_blank">https://docs.rtems.org/branches/master/eng/coding-conventions.html</a><br>
>><br>
>><br>
>> Yes.<br>
>><br>
>><br>
> I use enums as bit fields a lot. I use them in conjunction with objects that are the same enum.<br>
><br>
> I avoid using #define. In most situations you can't print them in a debugger and they imply restricted usage.<br>
><br>
> Is this an appropriate warning? Does it always mean that the enum should be replaced with a #define?<br>
><br>
> If it doesn't always apply then the style should make it clear when it should apply.<br>
<br>
We don't have to agree with Coverity. This is why I asked before the change:<br>
<br>
<a href="https://lists.rtems.org/pipermail/devel/2021-January/064105.html" rel="noreferrer noreferrer" target="_blank">https://lists.rtems.org/pipermail/devel/2021-January/064105.html</a><br>
<br>
From my point of view enums are useful for bit fields and I don't think <br>
this point of view is too exotic since debuggers such as GDB and <br>
Lauterbach support it. For example:<br>
<br>
enum a {<br>
A,<br>
B,<br>
C<br>
};<br>
<br>
enum a f(enum a x, enum a y)<br>
{<br>
return x | y;<br>
}<br>
<br>
enum a v;<br>
<br>
int main()<br>
{<br>
v = f(B, C);<br>
return 0;<br>
}<br>
<br>
Breakpoint 1, main () at test.c:16<br>
16 v = f(B, C);<br>
(gdb) n<br>
17 return 0;<br>
(gdb) p v<br>
$1 = (B | C)<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">If we want enums as bitfields, we can add that as a coding guideline as an option and mention that some static analysis tools do not like it.</div><div dir="auto"><br></div><div dir="auto">Then mark these all as ignored with an explanation</div></div></blockquote><div><br></div><div>My only concern is whether the behavior is always well-defined (by the C standards). I'm not an expert and don't know where to find an answer to that question. </div><div><br></div><div>What I seem to glean from a quick search is that the main requirement is that the type is guaranteed consistent with char, signed int, or unsigned int. So bit manipulations would seem to be well-defined. Does coverity offer any guidance why it complains?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
-- <br>
embedded brains GmbH<br>
Herr Sebastian HUBER<br>
Dornierstr. 4<br>
82178 Puchheim<br>
Germany<br>
email: <a href="mailto:sebastian.huber@embedded-brains.de" rel="noreferrer" target="_blank">sebastian.huber@embedded-brains.de</a><br>
phone: +49-89-18 94 741 - 16<br>
fax: +49-89-18 94 741 - 08<br>
<br>
Registergericht: Amtsgericht München<br>
Registernummer: HRB 157899<br>
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler<br>
Unsere Datenschutzerklärung finden Sie hier:<br>
<a href="https://embedded-brains.de/datenschutzerklaerung/" rel="noreferrer noreferrer" target="_blank">https://embedded-brains.de/datenschutzerklaerung/</a><br>
<br>
_______________________________________________<br>
devel mailing list<br>
<a href="mailto:devel@rtems.org" rel="noreferrer" target="_blank">devel@rtems.org</a><br>
<a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote></div></div></div>
</blockquote></div></div>