<?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 really just another question on pointer scope in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/really-just-another-question-on-pointer-scope/m-p/773526#M47028</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wrote this code to demonstrate something I found in the KSDK USB library. I took (interpreted?) this code from usb_device_ch9.c starting around line 862.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;typedef struct _usb_device_control_request_struct&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; usb_setup_struct_t *setup; /*!&amp;lt; The pointer of the setup packet data. */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint8_t *buffer;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*!&amp;lt; Pass the buffer address. */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t length;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*!&amp;lt; Pass the buffer length or requested length. */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint8_t isSetup;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*!&amp;lt; Indicates whether a setup packet is received. */&lt;BR /&gt;} usb_device_control_request_struct_t;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void main()&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;function1();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void function1()&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;uint8_t *buffer = (uint8_t *)NULL;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t length = 0U;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;usb_device_control_request_struct_t controlRequest;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;controlRequest.buffer = (uint8_t *)NULL&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;function2(&amp;amp;controlRequest);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;length = controlRequest.length;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;buffer = controlRequest.buffer;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;void function2(void* param)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;usb_device_control_request_struct_t* controlRequest = (usb_device_control_request_struct_t*)param;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;function3(controlRequest)&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;uint8_t buffer[8]&lt;BR /&gt;void function3(usb_device_control_request_struct_t* controlRequest)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;controlRequest.buffer = buffer;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;controlRequest.length = 8;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The expectation is function2 will give controlRequest.buffer something to point to but controlRequest.buffer is still null when in the context of function1() just after calling function2(). I would never do it this way but this is the framework of the KSDK USB driver. I'm probably forgetting to explain something here but hopefully I can at least get a conversation going?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 08 Jan 2018 22:15:10 GMT</pubDate>
    <dc:creator>ryanlush</dc:creator>
    <dc:date>2018-01-08T22:15:10Z</dc:date>
    <item>
      <title>really just another question on pointer scope</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/really-just-another-question-on-pointer-scope/m-p/773526#M47028</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wrote this code to demonstrate something I found in the KSDK USB library. I took (interpreted?) this code from usb_device_ch9.c starting around line 862.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;typedef struct _usb_device_control_request_struct&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; usb_setup_struct_t *setup; /*!&amp;lt; The pointer of the setup packet data. */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint8_t *buffer;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*!&amp;lt; Pass the buffer address. */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t length;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*!&amp;lt; Pass the buffer length or requested length. */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint8_t isSetup;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*!&amp;lt; Indicates whether a setup packet is received. */&lt;BR /&gt;} usb_device_control_request_struct_t;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void main()&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;function1();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void function1()&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;uint8_t *buffer = (uint8_t *)NULL;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t length = 0U;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;usb_device_control_request_struct_t controlRequest;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;controlRequest.buffer = (uint8_t *)NULL&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;function2(&amp;amp;controlRequest);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;length = controlRequest.length;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;buffer = controlRequest.buffer;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;void function2(void* param)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;usb_device_control_request_struct_t* controlRequest = (usb_device_control_request_struct_t*)param;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;function3(controlRequest)&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;uint8_t buffer[8]&lt;BR /&gt;void function3(usb_device_control_request_struct_t* controlRequest)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;controlRequest.buffer = buffer;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;controlRequest.length = 8;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The expectation is function2 will give controlRequest.buffer something to point to but controlRequest.buffer is still null when in the context of function1() just after calling function2(). I would never do it this way but this is the framework of the KSDK USB driver. I'm probably forgetting to explain something here but hopefully I can at least get a conversation going?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jan 2018 22:15:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/really-just-another-question-on-pointer-scope/m-p/773526#M47028</guid>
      <dc:creator>ryanlush</dc:creator>
      <dc:date>2018-01-08T22:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: really just another question on pointer scope</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/really-just-another-question-on-pointer-scope/m-p/773527#M47029</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;A _jive_internal="true" class="" data-content-finding="Community" data-userid="269275" data-username="ryanlush" href="https://community.nxp.com/people/ryanlush"&gt;Ryan Lush&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not sure I fully understand you, I copied your code to hello world project, and found the controlRequest.buffer point to 0x2002FFE0.&amp;nbsp; Please see below picture.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/618iB507CC82EED7E856/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.png" alt="pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Daniel&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Jan 2018 06:08:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/really-just-another-question-on-pointer-scope/m-p/773527#M47029</guid>
      <dc:creator>danielchen</dc:creator>
      <dc:date>2018-01-10T06:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: really just another question on pointer scope</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/really-just-another-question-on-pointer-scope/m-p/773528#M47030</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Isn't function3 wrong, among other issues?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;void function3(usb_device_control_request_struct_t* controlRequest)&lt;/SPAN&gt;&lt;BR style="color: #51626f; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;{&lt;/SPAN&gt;&lt;BR style="color: #51626f; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;controlRequest.buffer = buffer;&lt;/SPAN&gt;&lt;BR style="color: #51626f; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;controlRequest.length = 8;&lt;/SPAN&gt;&lt;BR style="color: #51626f; background-color: #ffffff;" /&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;should be:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;&amp;nbsp; &amp;nbsp;controlRequest-&amp;gt;buffer = buffer;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Jan 2018 13:22:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/really-just-another-question-on-pointer-scope/m-p/773528#M47030</guid>
      <dc:creator>bobpaddock</dc:creator>
      <dc:date>2018-01-10T13:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: really just another question on pointer scope</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/really-just-another-question-on-pointer-scope/m-p/773529#M47031</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, controlRequest is a pointer in function3, should be &lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;&amp;nbsp;controlRequest-&amp;gt;buffer = buffer;&amp;nbsp; or else there will be a compile error.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;Regards&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;Daniel&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Jan 2018 14:08:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/really-just-another-question-on-pointer-scope/m-p/773529#M47031</guid>
      <dc:creator>danielchen</dc:creator>
      <dc:date>2018-01-10T14:08:05Z</dc:date>
    </item>
  </channel>
</rss>

