cmemory-managementalloc

Alloc in programming language C


I am using the XDK Bosch Sensor for a project which is programmed in C. The idea is that the XDK should be able to connect to another network. SSID and password are sent via MQTT. It is already possible to connect the XDK to a network at initalization. In order to receive a MQTT message, the function shown below is used which was partly adapted by Guides of Bosch. Whenever a MQTT message is received this function is executed.

I am able to connect to a new network if I use following code in the function above instead of the arraySSID and arrayPwd even though arraySSID and arrayPwdshow the same content as testSSID and testPW when I print both on the console.

 char testSSID[] = "TestSSID";
 char testPW[] = "TestPwsd";
 Retcode_T connect_rc3 = NetworkSetup(&testSSID, &testPW);

If I compare arraySSID, arrayPwd and the size of testSSIDand testPwd, a different size is allocated to them. arraySSID, arrayPwd are always of size 4.

For doing so, I used following code:

 printf("%i \n", sizeof(arraySSID));
 printf("%i \n", sizeof(testSSID));

 printf("%d \n", sizeof(arrayPW));
 printf("%d \n", sizeof(testPW));

Solution

  • The problem was indeed a pointer problem.. By using

       Retcode_T connect_rc3 = NetworkSetup(arraySSID, arrayPW);
    

    the function worked perfectly fine. I did not consider that arrayPW is already of type char *, so that &arraySSID is of type char **.

    I also changed (IP <= CountNumberItemsIp) to (IP < CountNumberItemsIp).