<?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>LPC MicrocontrollersのトピックRe: LPCOpen bug : TRUE is false.</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPCOpen-bug-TRUE-is-false/m-p/584767#M21110</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by hparracho on Fri Aug 08 08:44:41 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: peufeu&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;Compiling the following code with lpc_types.h included :&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;#if True
#pragma message "TRUE is TRUE"
#else
#pragma message "TRUE is FALSE"
#endif

#ifdef True
#pragma message "TRUE is Defined"
#else
#pragma message "TRUE is Not Defined"
#endif&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;Gives this result :&lt;BR /&gt;&lt;BR /&gt;foo.c:40:9: note: #pragma message: TRUE is FALSE&lt;BR /&gt;foo.c:46:9: note: #pragma message: TRUE is Not Defined&lt;BR /&gt;&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;C/C++ is case sensitive.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"TRUE" is defined, "True" is not. The output is ok to me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 20:25:42 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T20:25:42Z</dc:date>
    <item>
      <title>LPCOpen bug : TRUE is false.</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPCOpen-bug-TRUE-is-false/m-p/584764#M21107</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by peufeu on Fri Aug 08 08:00:32 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;lpcopen2.12/lpc_chip_43xx/inc/lpc_types.h contains the following statement.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;typedef enum {FALSE = 0, TRUE = !FALSE} Bool;&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Compiling the following code with lpc_types.h included :&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;#if True
#pragma message "TRUE is TRUE"
#else
#pragma message "TRUE is FALSE"
#endif

#ifdef True
#pragma message "TRUE is Defined"
#else
#pragma message "TRUE is Not Defined"
#endif&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Gives this result :&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;foo.c:40:9: note: #pragma message: TRUE is FALSE&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;foo.c:46:9: note: #pragma message: TRUE is Not Defined&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Interesting. The preprecessor doesn't care about enums...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have libraries with conditional compiles like :&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
// in config.h
#define USE_FEATURE_FOO TRUE

// in some other file
#if USE_FEATURE_FOO
 .. implement foo ..
#endif
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This does not work if lpc_types is included...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Fix is to edit lpc_types.h and replace the typedef with the usual :&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;#define FALSE 0
#define TRUE&amp;nbsp; 1&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:25:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPCOpen-bug-TRUE-is-false/m-p/584764#M21107</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: LPCOpen bug : TRUE is false.</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPCOpen-bug-TRUE-is-false/m-p/584765#M21108</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by TheFallGuy on Fri Aug 08 08:12:33 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;That is a bug is your code and a misunderstanding of how the pre-processor works.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The pre-processor is a PRE_PROCESSOR - it processes the source code before the compiler gets to see it. It is simply a text processor that processes macros and knows nothing about enums, or any other C types or syntax.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To avoid the problems you are having when conditionally compiling code, you should be using the values 0 and 1 (or use 'defined') and not ANOTHER macro. If you try to do anything else, you will have problems with LPCOpen and MANY other libraries.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, either do this&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#define USE_FEATURE_FOO 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#if USE_FEATURE_FOO&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;or&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#define USE_FEATURE_FOO&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#ifdef USE_FEATURE_FOO&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;or &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#define USE_FEATURE_FOO&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#if defined(USE_FEATURE_FOO)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Learn about the C pre-processor here:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=https%3A%2F%2Fgcc.gnu.org%2Fonlinedocs%2Fcpp%2FOverview.html%23Overview" rel="nofollow" target="_blank"&gt;https://gcc.gnu.org/onlinedocs/cpp/Overview.html#Overview&lt;/A&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:25:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPCOpen-bug-TRUE-is-false/m-p/584765#M21108</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: LPCOpen bug : TRUE is false.</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPCOpen-bug-TRUE-is-false/m-p/584766#M21109</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by peufeu on Fri Aug 08 08:41:32 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: TheFallGuy&lt;/STRONG&gt;&lt;BR /&gt;The pre-processor is a PRE_PROCESSOR - it processes the source code before the compiler gets to see it. It is simply a text processor that processes macros and knows nothing about enums, or any other C types or syntax.&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Yep. This is why using enums for TRUE and FALSE constants is bad practice.&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:25:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPCOpen-bug-TRUE-is-false/m-p/584766#M21109</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: LPCOpen bug : TRUE is false.</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPCOpen-bug-TRUE-is-false/m-p/584767#M21110</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by hparracho on Fri Aug 08 08:44:41 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: peufeu&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;Compiling the following code with lpc_types.h included :&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;#if True
#pragma message "TRUE is TRUE"
#else
#pragma message "TRUE is FALSE"
#endif

#ifdef True
#pragma message "TRUE is Defined"
#else
#pragma message "TRUE is Not Defined"
#endif&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;Gives this result :&lt;BR /&gt;&lt;BR /&gt;foo.c:40:9: note: #pragma message: TRUE is FALSE&lt;BR /&gt;foo.c:46:9: note: #pragma message: TRUE is Not Defined&lt;BR /&gt;&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;C/C++ is case sensitive.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"TRUE" is defined, "True" is not. The output is ok to me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:25:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPCOpen-bug-TRUE-is-false/m-p/584767#M21110</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: LPCOpen bug : TRUE is false.</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPCOpen-bug-TRUE-is-false/m-p/584768#M21111</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by peufeu on Fri Aug 08 09:20:38 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;It's a copypaste mistake &lt;SPAN class="lia-unicode-emoji" title=":winking_face:"&gt;&lt;LI-EMOJI id="lia_winking-face" title=":winking_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's the real one :&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;typedef enum {FALSE = 0, TRUE = !FALSE} Bool;

#if TRUE
#pragma message "TRUE is TRUE"
#else
#pragma message "TRUE is FALSE"
#endif

#ifdef TRUE
#pragma message "TRUE is Defined"
#else
#pragma message "TRUE is Not Defined"
#endif&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;(It still says that TRUE is FALSE, but it now spits a warning, thanks to -Wundef now being activated).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:25:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPCOpen-bug-TRUE-is-false/m-p/584768#M21111</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: LPCOpen bug : TRUE is false.</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPCOpen-bug-TRUE-is-false/m-p/584769#M21112</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by hparracho on Wed Aug 13 03:22:36 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;The answer that TheFallGuy gave you basically sums it up perfectly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The pre-processor is a macro processor and runs before compilation. It knows nothing about the language and it's types.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It only understands macros defined with the #define keyword and literal values.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, if you want to test if a macro is defined you use #ifdef or #if defined(...)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want to test the value of a macro you use #if.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can also test the value of literals like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#if 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;or&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#if 'a'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In C "TRUE/FALSE" are not literals, but in C++ "true/false" are.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:25:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPCOpen-bug-TRUE-is-false/m-p/584769#M21112</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:25:43Z</dc:date>
    </item>
  </channel>
</rss>

