<?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>MCUXpresso SDK中的主题 RW612 SDK - C++ header guards improperly placed</title>
    <link>https://community.nxp.com/t5/MCUXpresso-SDK/RW612-SDK-C-header-guards-improperly-placed/m-p/2004596#M4998</link>
    <description>&lt;P&gt;I just ran into an issue with the RW612 SDK for MCUXpresso (v2.16.1).&amp;nbsp; Currently using the MCUX IDE, but this also affects VS CODE.&lt;/P&gt;&lt;P&gt;TL;DR - When compiling a C API module for C++, the&amp;nbsp;&lt;SPAN&gt;extern "C" { } declaration in the header file must surround ALL header file declarations, not just function declarations; otherwise, enum labels defined within structs will not appear in the global namespace as intended.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My issue... I'm writing a C++ driver for the RW612 FLEXCOMM UART, so naturally I'm calling the FSL driver API for the UART and the clock subsystem.&amp;nbsp; Here's my code snippet for attaching the FRG clock:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Source code, compile fails because of C++ namespace issue" style="width: 383px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/313376i240363068D71243D/image-size/large?v=v2&amp;amp;px=999" role="button" title="snippet_1.png" alt="Source code, compile fails because of C++ namespace issue" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Source code, compile fails because of C++ namespace issue&lt;/span&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;But when I compile this, I get an error "'kCLOCK_FrgPllDiv' was not declared in this scope".&amp;nbsp; Well, that's strange, I can see the definition for&amp;nbsp;kCLOCK_FrgPllDiv in fsl_clock.h.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Definition of kCLOCK_FrgPllDiv" style="width: 480px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/313377i9B45371E6A941EE7/image-size/large?v=v2&amp;amp;px=999" role="button" title="snippet_2.png" alt="Definition of kCLOCK_FrgPllDiv" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Definition of kCLOCK_FrgPllDiv&lt;/span&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Then I realized... I wonder if this is a namespace thing.&amp;nbsp; Turns out, yes it is, because the extern "C" { } declaration is improperly placed.&amp;nbsp; It's only surrounding the C functions in fsl_clock.h; it is NOT surrounding any of the data type declarations in fsl_clock.h, including the definition of clock_frg_clk_config_t.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In C, all enum labels are in the global namespace, even if they are defined within a structure (such as here).&amp;nbsp; In C++, any data type or label defined within a struct, even a "weak" enum label, is scoped by the name of the struct and requires x::y syntax to use.&amp;nbsp; In order to get my code fragment above to compile correctly, I have to write:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="&amp;quot;Fixed&amp;quot; code using struct type name::enum label" style="width: 489px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/313378i8E882AC1561012FA/image-size/large?v=v2&amp;amp;px=999" role="button" title="snippet_3.png" alt="&amp;quot;Fixed&amp;quot; code using struct type name::enum label" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;"Fixed" code using struct type name::enum label&lt;/span&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This is not correct behavior for a native C code module.&amp;nbsp; Moving the extern "C" opening declaration to near the start of the header file (say, line 18) will have no side effects for C code and in C++ will cause all enum labels to appear in the global namespace as intended, regardless of where they are defined.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;fsl_clock.h is the only header file currently giving me this issue, but I can see in other FSL header files that the extern "C" { } block is similarly positioned (fsl_flexcomm.h, fsl_gdma.h, etc).&amp;nbsp; You need to fix all of these header files and update your coding standards documentation to prevent this specific issue occurring in the future.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Dana M.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 01 Dec 2024 20:34:33 GMT</pubDate>
    <dc:creator>dmarks_ls</dc:creator>
    <dc:date>2024-12-01T20:34:33Z</dc:date>
    <item>
      <title>RW612 SDK - C++ header guards improperly placed</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/RW612-SDK-C-header-guards-improperly-placed/m-p/2004596#M4998</link>
      <description>&lt;P&gt;I just ran into an issue with the RW612 SDK for MCUXpresso (v2.16.1).&amp;nbsp; Currently using the MCUX IDE, but this also affects VS CODE.&lt;/P&gt;&lt;P&gt;TL;DR - When compiling a C API module for C++, the&amp;nbsp;&lt;SPAN&gt;extern "C" { } declaration in the header file must surround ALL header file declarations, not just function declarations; otherwise, enum labels defined within structs will not appear in the global namespace as intended.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My issue... I'm writing a C++ driver for the RW612 FLEXCOMM UART, so naturally I'm calling the FSL driver API for the UART and the clock subsystem.&amp;nbsp; Here's my code snippet for attaching the FRG clock:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Source code, compile fails because of C++ namespace issue" style="width: 383px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/313376i240363068D71243D/image-size/large?v=v2&amp;amp;px=999" role="button" title="snippet_1.png" alt="Source code, compile fails because of C++ namespace issue" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Source code, compile fails because of C++ namespace issue&lt;/span&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;But when I compile this, I get an error "'kCLOCK_FrgPllDiv' was not declared in this scope".&amp;nbsp; Well, that's strange, I can see the definition for&amp;nbsp;kCLOCK_FrgPllDiv in fsl_clock.h.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Definition of kCLOCK_FrgPllDiv" style="width: 480px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/313377i9B45371E6A941EE7/image-size/large?v=v2&amp;amp;px=999" role="button" title="snippet_2.png" alt="Definition of kCLOCK_FrgPllDiv" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Definition of kCLOCK_FrgPllDiv&lt;/span&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Then I realized... I wonder if this is a namespace thing.&amp;nbsp; Turns out, yes it is, because the extern "C" { } declaration is improperly placed.&amp;nbsp; It's only surrounding the C functions in fsl_clock.h; it is NOT surrounding any of the data type declarations in fsl_clock.h, including the definition of clock_frg_clk_config_t.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In C, all enum labels are in the global namespace, even if they are defined within a structure (such as here).&amp;nbsp; In C++, any data type or label defined within a struct, even a "weak" enum label, is scoped by the name of the struct and requires x::y syntax to use.&amp;nbsp; In order to get my code fragment above to compile correctly, I have to write:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="&amp;quot;Fixed&amp;quot; code using struct type name::enum label" style="width: 489px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/313378i8E882AC1561012FA/image-size/large?v=v2&amp;amp;px=999" role="button" title="snippet_3.png" alt="&amp;quot;Fixed&amp;quot; code using struct type name::enum label" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;"Fixed" code using struct type name::enum label&lt;/span&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This is not correct behavior for a native C code module.&amp;nbsp; Moving the extern "C" opening declaration to near the start of the header file (say, line 18) will have no side effects for C code and in C++ will cause all enum labels to appear in the global namespace as intended, regardless of where they are defined.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;fsl_clock.h is the only header file currently giving me this issue, but I can see in other FSL header files that the extern "C" { } block is similarly positioned (fsl_flexcomm.h, fsl_gdma.h, etc).&amp;nbsp; You need to fix all of these header files and update your coding standards documentation to prevent this specific issue occurring in the future.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Dana M.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Dec 2024 20:34:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/RW612-SDK-C-header-guards-improperly-placed/m-p/2004596#M4998</guid>
      <dc:creator>dmarks_ls</dc:creator>
      <dc:date>2024-12-01T20:34:33Z</dc:date>
    </item>
    <item>
      <title>Re: RW612 SDK - C++ header guards improperly placed</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/RW612-SDK-C-header-guards-improperly-placed/m-p/2004639#M4999</link>
      <description>&lt;P&gt;Dear&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/53251"&gt;@dmarks_ls&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your kindly feedback!&lt;/P&gt;
&lt;P&gt;I will escalate it to internal team.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;weidong&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2024 01:38:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/RW612-SDK-C-header-guards-improperly-placed/m-p/2004639#M4999</guid>
      <dc:creator>weidong_sun</dc:creator>
      <dc:date>2024-12-02T01:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: RW612 SDK - C++ header guards improperly placed</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/RW612-SDK-C-header-guards-improperly-placed/m-p/2009761#M5011</link>
      <description>&lt;P&gt;Dear&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/53251"&gt;@dmarks_ls&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Internal team could not reproduce the issue you encountered , could you please share your project with us?&lt;/P&gt;
&lt;P&gt;If yes, you can send it to me directly over email.&lt;/P&gt;
&lt;P&gt;My email is : &lt;A href="mailto:weidong.sun@nxp.com" target="_blank"&gt;weidong.sun@nxp.com&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;weidong&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 06:53:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/RW612-SDK-C-header-guards-improperly-placed/m-p/2009761#M5011</guid>
      <dc:creator>weidong_sun</dc:creator>
      <dc:date>2024-12-09T06:53:15Z</dc:date>
    </item>
    <item>
      <title>Re: RW612 SDK - C++ header guards improperly placed</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/RW612-SDK-C-header-guards-improperly-placed/m-p/2010305#M5012</link>
      <description>&lt;P&gt;Not sure why your engineers couldn't reproduce the issue.&amp;nbsp; Here is the code to demonstrate the issue:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;/* This code tests whether the enum definitions in clock_frg_clk_config_t are
 * in the global C namespace (as they should be) or are scoped within the
 * struct (which is a C++-only behavior). */

#define DEMONSTRATE_COMPILER_FAILURE    1

#include &amp;lt;fsl_clock.h&amp;gt;

void CPP_TestScopedLabels(void) {
  clock_frg_clk_config_t frg_config;
#if DEMONSTRATE_COMPILER_FAILURE
  /* This would be correct code if this module was being compiled as a C
   * translation unit.  But when it is compiled as C++, the compiler throws
   * an error because kCLOCK_FrgPllDiv is not in the global namespace; it is
   * instead scoped by clock_frg_clk_config_t. */
  frg_config.sfg_clock_src=kCLOCK_FrgPllDiv;
#else
  /* This code qualifies the enum label with the type name of the struct.
   * This is not necessary in C because all enum are "weak" and all enum labels
   * appear in the global namespace, regardless of where they are defined. */
  frg_config.sfg_clock_src=clock_frg_clk_config_t::kCLOCK_FrgPllDiv;
#endif
  (void) frg_config;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have included the source file as well.&amp;nbsp; (As an aside, your forum software does NOT accept files with a CPP extension, only C.&amp;nbsp; PLEASE FIX THIS.)&lt;/P&gt;&lt;P&gt;Dana M.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 15:53:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/RW612-SDK-C-header-guards-improperly-placed/m-p/2010305#M5012</guid>
      <dc:creator>dmarks_ls</dc:creator>
      <dc:date>2024-12-09T15:53:43Z</dc:date>
    </item>
    <item>
      <title>Re: RW612 SDK - C++ header guards improperly placed</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/RW612-SDK-C-header-guards-improperly-placed/m-p/2016750#M5028</link>
      <description>&lt;P&gt;Dear&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/53251"&gt;@dmarks_ls&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I got feedback from internal team, see below, please!&lt;/P&gt;
&lt;P&gt;==========================================&lt;/P&gt;
&lt;P&gt;We can reproduce issue now, it is related to enum definition in struct definition only, it is not related to common prototype defintion.&lt;/P&gt;
&lt;P&gt;SW team will fix this issue in next release&lt;/P&gt;
&lt;P&gt;==========================================&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;weidong&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2024 02:38:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/RW612-SDK-C-header-guards-improperly-placed/m-p/2016750#M5028</guid>
      <dc:creator>weidong_sun</dc:creator>
      <dc:date>2024-12-19T02:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: RW612 SDK - C++ header guards improperly placed</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/RW612-SDK-C-header-guards-improperly-placed/m-p/2017306#M5032</link>
      <description>&lt;P&gt;Thanks for getting back to me.&amp;nbsp; To be clear, the enum definition inside the struct is not the actual problem... the problem is the misplacement of C++ guards ("extern "C" { }) in this and many other SDK header files.&amp;nbsp; Please make sure you treat the root cause, not merely the symptom.&amp;nbsp; Thanks.&lt;/P&gt;&lt;P&gt;Dana M.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2024 15:49:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/RW612-SDK-C-header-guards-improperly-placed/m-p/2017306#M5032</guid>
      <dc:creator>dmarks_ls</dc:creator>
      <dc:date>2024-12-19T15:49:18Z</dc:date>
    </item>
  </channel>
</rss>

