<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Enabling warning for incorrect enum assignment in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Enabling-warning-for-incorrect-enum-assignment/m-p/641603#M38869</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN&gt;-Wpedantic and -Wextra will enable other warnings beyond&amp;nbsp;-Wall.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;However C has limited type system compared to that of C++.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What you are really after is Lint. &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A class="link-titled" href="http://www.gimpel.com/html/index.htm" title="http://www.gimpel.com/html/index.htm"&gt;The Leader in Static Analysis for C/C++ -- PC-lint and FlexeLint&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;which is what I use myself.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# -Wenum-compare:&lt;BR /&gt;# Warn about a comparison between values of different enumerated&lt;BR /&gt;# types. In C++ enumeral mismatches in conditional expressions are&lt;BR /&gt;# also diagnosed and the warning is enabled by default. In C this&lt;BR /&gt;# warning is enabled by -Wall.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CFLAGS += -Wextra&lt;BR /&gt;CPPFLAGS += -Wextra&lt;BR /&gt;# -Wextra:&lt;BR /&gt;# This enables some extra warning flags that are not enabled by&lt;BR /&gt;# -Wall.&lt;BR /&gt;#&lt;BR /&gt;# -Wclobbered&lt;BR /&gt;# -Wempty-body&lt;BR /&gt;# -Wignored-qualifiers&lt;BR /&gt;# -Wmissing-field-initializers&lt;BR /&gt;# -Wmissing-parameter-type (C only)&lt;BR /&gt;# -Wold-style-declaration (C only)&lt;BR /&gt;# -Woverride-init&lt;BR /&gt;# -Wsign-compare&lt;BR /&gt;# -Wtype-limits&lt;BR /&gt;# -Wuninitialized&lt;BR /&gt;# -Wunused-parameter (only with -Wunused or -Wall)&lt;BR /&gt;# -Wunused-but-set-parameter (only with -Wunused or -Wall)&lt;BR /&gt;#&lt;BR /&gt;# The option -Wextra also prints warning messages for the following cases:&lt;BR /&gt;#&lt;BR /&gt;# A pointer is compared against integer zero with ‘&amp;lt;’, ‘&amp;lt;=’, ‘&amp;gt;’, or ‘&amp;gt;=’.&lt;BR /&gt;# (C++ only) An enumerator and a non-enumerator both appear in a conditional expression.&lt;BR /&gt;# (C++ only) Ambiguous virtual bases.&lt;BR /&gt;# (C++ only) Subscripting an array that has been declared ‘register’.&lt;BR /&gt;# (C++ only) Taking the address of a variable that has been declared ‘register’.&lt;BR /&gt;# (C++ only) A base class is not initialized in a derived class's copy constructor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#CFLAGS += -Wpedantic&lt;BR /&gt;#CPPFLAGS += -Wpedantic&lt;BR /&gt;#-Wpedantic&lt;BR /&gt;# Issue all the warnings demanded by strict ISO C and ISO C++; reject&lt;BR /&gt;# all programs that use forbidden extensions, and some other programs&lt;BR /&gt;# that do not follow ISO C and ISO C++. For ISO C, follows the version&lt;BR /&gt;# of the ISO C standard specified by any -std option used. Valid ISO&lt;BR /&gt;# C and ISO C++ programs should compile properly with or without this&lt;BR /&gt;# option (though a rare few require -ansi or a -std option specifying&lt;BR /&gt;# the required version of ISO C). However, without this option,&lt;BR /&gt;# certain GNU extensions and traditional C and C++ features are&lt;BR /&gt;# supported as well. With this option, they are rejected.&lt;BR /&gt;#&lt;BR /&gt;# Some users try to use -Wpedantic to check programs for strict ISO C&lt;BR /&gt;# conformance. They soon find that it does not do quite what they&lt;BR /&gt;# want: it finds some non-ISO practices, but not all—only those for&lt;BR /&gt;# which ISO C requires a diagnostic, and some others for which&lt;BR /&gt;# diagnostics have been added.&lt;/P&gt;&lt;P&gt;#CFLAGS += -pedantic-errors&lt;BR /&gt;#CPPFLAGS += -pedantic-errors&lt;BR /&gt;# Like -Wpedantic, except that errors are produced rather than warnings.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 02 Dec 2016 13:57:45 GMT</pubDate>
    <dc:creator>bobpaddock</dc:creator>
    <dc:date>2016-12-02T13:57:45Z</dc:date>
    <item>
      <title>Enabling warning for incorrect enum assignment</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Enabling-warning-for-incorrect-enum-assignment/m-p/641602#M38868</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like to know how I can enable warnings for incorrect enum assignment or being passed as function parameter. Here is an example&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;typedef enum&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;{&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;TEST_1A = 0,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;TEST_2A = 1&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;} test_1_t;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;typedef enum&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;{&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;TEST_1B = 0,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;TEST_2B = 1&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;} test_2_t;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I declare you variables,&amp;nbsp;&lt;/P&gt;&lt;P&gt;test_1_t Var1;&lt;/P&gt;&lt;P&gt;test_2_t Var2;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #993300;"&gt;&lt;EM&gt;&lt;STRONG&gt;Var2 = TEST_1A;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// this line should cause a &lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;warning&lt;/STRONG&gt;&lt;/SPAN&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can someone please let me know if how to enable this? &lt;SPAN style="color: #008000;"&gt;&lt;EM style="text-decoration: underline;"&gt;I've already enabled -Wall&lt;/EM&gt;&lt;/SPAN&gt; but that doesn't seem to work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Santhosh&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/michaelsteffenfae"&gt;michaelsteffenfae&lt;/A&gt;‌&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Dec 2016 23:33:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Enabling-warning-for-incorrect-enum-assignment/m-p/641602#M38868</guid>
      <dc:creator>srcoolz</dc:creator>
      <dc:date>2016-12-01T23:33:22Z</dc:date>
    </item>
    <item>
      <title>Re: Enabling warning for incorrect enum assignment</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Enabling-warning-for-incorrect-enum-assignment/m-p/641603#M38869</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN&gt;-Wpedantic and -Wextra will enable other warnings beyond&amp;nbsp;-Wall.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;However C has limited type system compared to that of C++.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What you are really after is Lint. &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A class="link-titled" href="http://www.gimpel.com/html/index.htm" title="http://www.gimpel.com/html/index.htm"&gt;The Leader in Static Analysis for C/C++ -- PC-lint and FlexeLint&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;which is what I use myself.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# -Wenum-compare:&lt;BR /&gt;# Warn about a comparison between values of different enumerated&lt;BR /&gt;# types. In C++ enumeral mismatches in conditional expressions are&lt;BR /&gt;# also diagnosed and the warning is enabled by default. In C this&lt;BR /&gt;# warning is enabled by -Wall.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CFLAGS += -Wextra&lt;BR /&gt;CPPFLAGS += -Wextra&lt;BR /&gt;# -Wextra:&lt;BR /&gt;# This enables some extra warning flags that are not enabled by&lt;BR /&gt;# -Wall.&lt;BR /&gt;#&lt;BR /&gt;# -Wclobbered&lt;BR /&gt;# -Wempty-body&lt;BR /&gt;# -Wignored-qualifiers&lt;BR /&gt;# -Wmissing-field-initializers&lt;BR /&gt;# -Wmissing-parameter-type (C only)&lt;BR /&gt;# -Wold-style-declaration (C only)&lt;BR /&gt;# -Woverride-init&lt;BR /&gt;# -Wsign-compare&lt;BR /&gt;# -Wtype-limits&lt;BR /&gt;# -Wuninitialized&lt;BR /&gt;# -Wunused-parameter (only with -Wunused or -Wall)&lt;BR /&gt;# -Wunused-but-set-parameter (only with -Wunused or -Wall)&lt;BR /&gt;#&lt;BR /&gt;# The option -Wextra also prints warning messages for the following cases:&lt;BR /&gt;#&lt;BR /&gt;# A pointer is compared against integer zero with ‘&amp;lt;’, ‘&amp;lt;=’, ‘&amp;gt;’, or ‘&amp;gt;=’.&lt;BR /&gt;# (C++ only) An enumerator and a non-enumerator both appear in a conditional expression.&lt;BR /&gt;# (C++ only) Ambiguous virtual bases.&lt;BR /&gt;# (C++ only) Subscripting an array that has been declared ‘register’.&lt;BR /&gt;# (C++ only) Taking the address of a variable that has been declared ‘register’.&lt;BR /&gt;# (C++ only) A base class is not initialized in a derived class's copy constructor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#CFLAGS += -Wpedantic&lt;BR /&gt;#CPPFLAGS += -Wpedantic&lt;BR /&gt;#-Wpedantic&lt;BR /&gt;# Issue all the warnings demanded by strict ISO C and ISO C++; reject&lt;BR /&gt;# all programs that use forbidden extensions, and some other programs&lt;BR /&gt;# that do not follow ISO C and ISO C++. For ISO C, follows the version&lt;BR /&gt;# of the ISO C standard specified by any -std option used. Valid ISO&lt;BR /&gt;# C and ISO C++ programs should compile properly with or without this&lt;BR /&gt;# option (though a rare few require -ansi or a -std option specifying&lt;BR /&gt;# the required version of ISO C). However, without this option,&lt;BR /&gt;# certain GNU extensions and traditional C and C++ features are&lt;BR /&gt;# supported as well. With this option, they are rejected.&lt;BR /&gt;#&lt;BR /&gt;# Some users try to use -Wpedantic to check programs for strict ISO C&lt;BR /&gt;# conformance. They soon find that it does not do quite what they&lt;BR /&gt;# want: it finds some non-ISO practices, but not all—only those for&lt;BR /&gt;# which ISO C requires a diagnostic, and some others for which&lt;BR /&gt;# diagnostics have been added.&lt;/P&gt;&lt;P&gt;#CFLAGS += -pedantic-errors&lt;BR /&gt;#CPPFLAGS += -pedantic-errors&lt;BR /&gt;# Like -Wpedantic, except that errors are produced rather than warnings.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2016 13:57:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Enabling-warning-for-incorrect-enum-assignment/m-p/641603#M38869</guid>
      <dc:creator>bobpaddock</dc:creator>
      <dc:date>2016-12-02T13:57:45Z</dc:date>
    </item>
    <item>
      <title>Re: Enabling warning for incorrect enum assignment</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Enabling-warning-for-incorrect-enum-assignment/m-p/641604#M38870</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Santhosh,&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; color: #1f497d;"&gt;In ANSI-C enumeration are of type ‘int’. So there is no reason for the compiler to have a warning for what &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; color: #1f497d;"&gt;Enums in C are really like int's like&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; color: #1f497d;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; color: #1f497d;"&gt;int &amp;nbsp;i = 3;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; color: #1f497d;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; color: #1f497d;"&gt;Likewise, you can do any things with enumeration exactly what you can do with ints.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; color: #1f497d;"&gt;e.g.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; color: #1f497d;"&gt;Var2 = (TEST_1A+TEST_2B)/TEST_2A;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; color: #1f497d;"&gt;Is legal and allowed in the C programming language. Again: enumerations are just ‘int’s by the rule of the language.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; color: #1f497d;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; color: #1f497d;"&gt;The mentioned PC-lint checker is a good suggestion. If you want to have a warning (actually: an error without a proper cast), then he should write and use this in C++.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; color: #1f497d;"&gt;In C++ enumerations are not of type ‘int’, but a distinct type (for each enumeration). Actually that’s the main benefit for using C++: it provides stronger type checking and flags many things like the above one as an error. I think this is what you could consider if you want to catch things like this. Another option is to compiler the C sources as C++ ones, but this will likely flag other things too (which might be a good thing).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; color: #1f497d;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; color: #1f497d;"&gt;I hope this helps,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; color: #1f497d;"&gt;Erich&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Dec 2016 06:11:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Enabling-warning-for-incorrect-enum-assignment/m-p/641604#M38870</guid>
      <dc:creator>BlackNight</dc:creator>
      <dc:date>2016-12-06T06:11:55Z</dc:date>
    </item>
    <item>
      <title>Re: Enabling warning for incorrect enum assignment</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Enabling-warning-for-incorrect-enum-assignment/m-p/641605#M38871</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you so much for the detailed explanation - I came to the same conclusion that has been suggested in the posts. The static analysis tool is a good option. But the way I've solved it is by compiling the code with C++ compiler.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I had to make few changes to have the code compatible both in C and C++, the most notable is the ISR. Here is a link for changing the ISR -&amp;nbsp;&lt;A href="https://community.nxp.com/message/630632"&gt;https://community.nxp.com/message/630632&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks once again for all your help.&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Santhosh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Dec 2016 15:18:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Enabling-warning-for-incorrect-enum-assignment/m-p/641605#M38871</guid>
      <dc:creator>srcoolz</dc:creator>
      <dc:date>2016-12-06T15:18:25Z</dc:date>
    </item>
  </channel>
</rss>

