<?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>LPCXpresso IDE中的主题 Re: int main(void) vs void main(void)</title>
    <link>https://community.nxp.com/t5/LPCXpresso-IDE/int-main-void-vs-void-main-void/m-p/550306#M11380</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by CodeRedSupport on Wed May 11 08:41:43 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: larryvc&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;So why do we have int main(void) in LPCXpresso? A return value is not necessary as the catch loop does not use it.&lt;BR /&gt; &lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To be honest, in the testing I have done - it basically makes no difference. Feel free to post an example where it does if you have one.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One thing to note is that although the default code provided in main.c by the project wizard includes an infinite while(1) loop - you can actually remove this if you are using the standard startup file, as this actually contains a while(1) loop after the call to main()/__main() anyway.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Having the while(1) in main() just makes the loop more obvious, and as it increments a counter, makes it easier to see that the loop is looping.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;CodeRedSupport&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 22:07:09 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T22:07:09Z</dc:date>
    <item>
      <title>int main(void) vs void main(void)</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/int-main-void-vs-void-main-void/m-p/550303#M11377</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by larryvc on Tue May 10 22:50:24 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;CodeRedSupport,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I know that the underlying reason of int main(void) is due to GCC historical reasons for operating systems,&amp;nbsp; but we can't run a true operating system on these MCUs anyways.&amp;nbsp; Also returning from main() is a no-no.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;So why do we have int main(void) in LPCXpresso? A return value is not necessary as the catch loop does not use it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wouldn't it make more sense to have void main(void)?&amp;nbsp; It would reinforce the fact that we do not return.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 22:07:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/int-main-void-vs-void-main-void/m-p/550303#M11377</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T22:07:07Z</dc:date>
    </item>
    <item>
      <title>Re: int main(void) vs void main(void)</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/int-main-void-vs-void-main-void/m-p/550304#M11378</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by atomicdog on Tue May 10 23:56:15 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I believe int main() is required by the C standard, at least for a non-freestanding environment.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 22:07:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/int-main-void-vs-void-main-void/m-p/550304#M11378</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T22:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: int main(void) vs void main(void)</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/int-main-void-vs-void-main-void/m-p/550305#M11379</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by larryvc on Wed May 11 08:15:59 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: atomicdog&lt;/STRONG&gt;&lt;BR /&gt;I believe int main() is required by the C standard, at least for a non-freestanding environment.&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi John,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes that was what I was trying to say above, but we are mostly working on freestanding environments while using LPCXpresso and I don't have a CodeRed version but I imagine there as well.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 22:07:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/int-main-void-vs-void-main-void/m-p/550305#M11379</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T22:07:09Z</dc:date>
    </item>
    <item>
      <title>Re: int main(void) vs void main(void)</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/int-main-void-vs-void-main-void/m-p/550306#M11380</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by CodeRedSupport on Wed May 11 08:41:43 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: larryvc&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;So why do we have int main(void) in LPCXpresso? A return value is not necessary as the catch loop does not use it.&lt;BR /&gt; &lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To be honest, in the testing I have done - it basically makes no difference. Feel free to post an example where it does if you have one.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One thing to note is that although the default code provided in main.c by the project wizard includes an infinite while(1) loop - you can actually remove this if you are using the standard startup file, as this actually contains a while(1) loop after the call to main()/__main() anyway.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Having the while(1) in main() just makes the loop more obvious, and as it increments a counter, makes it easier to see that the loop is looping.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;CodeRedSupport&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 22:07:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/int-main-void-vs-void-main-void/m-p/550306#M11380</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T22:07:09Z</dc:date>
    </item>
    <item>
      <title>Re: int main(void) vs void main(void)</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/int-main-void-vs-void-main-void/m-p/550307#M11381</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by larryvc on Wed May 11 09:19:04 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: CodeRedSupport&lt;/STRONG&gt;&lt;BR /&gt;To be honest, in the testing I have done - it basically makes no difference. Feel free to post an example where it does if you have one.&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I was only exploring the "why",&amp;nbsp; I have no examples, yet.;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: CodeRedSupport&lt;/STRONG&gt;&lt;BR /&gt; &lt;BR /&gt;...if you are using the standard startup file, as this actually contains a while(1) loop after the call to main()/__main() anyway.&lt;BR /&gt;&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That was the "catch loop" I mentioned above.&amp;nbsp; It's a good place to drop our code into.&amp;nbsp; The realm of "no main's land".:)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 22:07:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/int-main-void-vs-void-main-void/m-p/550307#M11381</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T22:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: int main(void) vs void main(void)</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/int-main-void-vs-void-main-void/m-p/550308#M11382</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by larryvc on Wed May 11 18:33:26 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;There is quite a discussion on another forum about this. Some quotes:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: &lt;/STRONG&gt;&lt;BR /&gt;You must use '[B]void[/B] [B]main[/B]()' as any sane person would.&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That would probably not apply to me.;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: &lt;/STRONG&gt;&lt;BR /&gt;As such the "[B]void[/B] [B]main[/B]([B]void[/B])" used by CV (and others I think) is far more sensible for an MCU.&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: &lt;/STRONG&gt;&lt;BR /&gt;As far as I have always understood,&amp;nbsp; you can use int [B]main[/B]() or [B]void[/B] [B]main[/B]() as appropriate.&lt;BR /&gt; &lt;BR /&gt;Without an operating system,&amp;nbsp; [B]void[/B] seems 'appropriate' to me.&amp;nbsp;&amp;nbsp;&amp;nbsp; So I would instinctively use [B]void[/B] [B]main[/B]().&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;As you said, it basically makes no difference, but the latter makes the most sense.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Larry&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 22:07:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/int-main-void-vs-void-main-void/m-p/550308#M11382</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T22:07:10Z</dc:date>
    </item>
  </channel>
</rss>

