<?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>Kinetis Microcontrollers中的主题 initialized and declared 'extern' [enabled by default]</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/initialized-and-declared-extern-enabled-by-default/m-p/304793#M12909</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We are using Coderwarior 10.5.&lt;/P&gt;&lt;P&gt;We are porting a Coldfire program to a K20 MK20DX128vlh5.&lt;/P&gt;&lt;P&gt;The GCC compiler complains of initialized and declared 'extern' [enabled by default] for all my external variables. &lt;/P&gt;&lt;P&gt;As an example&lt;/P&gt;&lt;P&gt;In the .h file I have &lt;/P&gt;&lt;P&gt;extern const char stCR[2];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the .c file I have &lt;/P&gt;&lt;P&gt;extern const char stCRLF[]={"\r\n\0"};&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This works fine for the Coldfire compiler but the GCC compiler gives a warning for every one of my variables declared as external.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is the proper syntax to do the same thing in GCC?&lt;/P&gt;&lt;P&gt;Or can this warning be safely ignored?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 26 Mar 2014 20:03:11 GMT</pubDate>
    <dc:creator>randenewberry</dc:creator>
    <dc:date>2014-03-26T20:03:11Z</dc:date>
    <item>
      <title>initialized and declared 'extern' [enabled by default]</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/initialized-and-declared-extern-enabled-by-default/m-p/304793#M12909</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We are using Coderwarior 10.5.&lt;/P&gt;&lt;P&gt;We are porting a Coldfire program to a K20 MK20DX128vlh5.&lt;/P&gt;&lt;P&gt;The GCC compiler complains of initialized and declared 'extern' [enabled by default] for all my external variables. &lt;/P&gt;&lt;P&gt;As an example&lt;/P&gt;&lt;P&gt;In the .h file I have &lt;/P&gt;&lt;P&gt;extern const char stCR[2];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the .c file I have &lt;/P&gt;&lt;P&gt;extern const char stCRLF[]={"\r\n\0"};&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This works fine for the Coldfire compiler but the GCC compiler gives a warning for every one of my variables declared as external.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is the proper syntax to do the same thing in GCC?&lt;/P&gt;&lt;P&gt;Or can this warning be safely ignored?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Mar 2014 20:03:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/initialized-and-declared-extern-enabled-by-default/m-p/304793#M12909</guid>
      <dc:creator>randenewberry</dc:creator>
      <dc:date>2014-03-26T20:03:11Z</dc:date>
    </item>
    <item>
      <title>Re: initialized and declared 'extern' [enabled by default]</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/initialized-and-declared-extern-enabled-by-default/m-p/304794#M12910</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You will get complains due to&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;extern const char stCRLF[]={"\r\n\0"};&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;when you have &lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;extern const char stCR[2];&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;since it is "declared" extern &lt;SPAN style="text-decoration: underline;"&gt;but&lt;/SPAN&gt; "initialised" extern. GCC warns as default and other compilers may do, depending on the level of warning/error settings.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is no need to initialise extern when already declared extern so I would remove the extern for all global variables since these 'should' be declared in a header anyway, otherwise they shouldn't be global and so should be static. The warning "could" be ignored since it doesin't cause a problem but people will tend not to trust code with warnings so probably best to drop the externs where initialsiation takes place....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Mar 2014 22:35:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/initialized-and-declared-extern-enabled-by-default/m-p/304794#M12910</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2014-03-26T22:35:11Z</dc:date>
    </item>
    <item>
      <title>Re: initialized and declared 'extern' [enabled by default]</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/initialized-and-declared-extern-enabled-by-default/m-p/304795#M12911</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rande,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You usually associate &lt;STRONG&gt;extern&lt;/STRONG&gt; with the &lt;STRONG&gt;declaration&lt;/STRONG&gt; of a variable i.e. indicating that it exists somewhere.&lt;/P&gt;&lt;P&gt;You &lt;STRONG&gt;define&lt;/STRONG&gt; the variable without the &lt;STRONG&gt;extern.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;...but&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;if you initialise a variable it is always considered a &lt;STRONG&gt;definition &lt;/STRONG&gt;irrespective of the &lt;STRONG&gt;extern&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So in summary:&lt;/P&gt;&lt;P&gt;In header file (.h)&amp;nbsp; where you are &lt;STRONG&gt;declaring&lt;/STRONG&gt; the variable use&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;extern const char stCR[2];&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;In the actual file (.c file) where you are &lt;STRONG&gt;defining&lt;/STRONG&gt; (creating) use&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;const char stCR[2] = "ab";&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;This also applies even if not initialising the variable e.g not a constant.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;It is only considered a warning but it is best to adopt the suggested approach.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;PS.&amp;nbsp; I presume the inconsistencies in the example in your question are a typo? Otherwise they are different variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;bye&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; &lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Mar 2014 22:49:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/initialized-and-declared-extern-enabled-by-default/m-p/304795#M12911</guid>
      <dc:creator>pgo</dc:creator>
      <dc:date>2014-03-26T22:49:52Z</dc:date>
    </item>
  </channel>
</rss>

