title: How to get float value from uint32_t?
body: <p>i use this part of code to read float value from OSC message on my microcontroller. However i get "dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]" error and no value is showed on printf. Is there any workaround for this one? marker is in struct as:</p>
  
  <pre><code>char *marker;  // the current read head
  </code></pre>
  
  
  
  <pre><code>float tosc_getNextFloat(tosc_message *o) {
    // convert from big-endian (network btye order)
    const uint32_t i = ntohl(*((uint32_t *) o-&gt;marker));
    o-&gt;marker += 4;
    return *((float *) (&amp;i));  &lt;---- this line of code does the error
  }
  </code></pre>
  
  <p>EDIT : </p>
  
  <p>So, i recieve data from microcontrollers internet chip over udp using function:</p>
  
  <pre><code>datasize_t recvfrom(uint8_t sn, uint8_t * buf, datasize_t len, uint8_t * addr, uint16_t *port, uint8_t *addrlen) //&lt;- general 
  </code></pre>
  
  <p>then i run another function to parse osc message:</p>
  
  <pre><code>tosc_parseMessage(&amp;A, (char*) buf, received_size); //&lt;- how i wrote parameters
  </code></pre>
  
  <p>where A is structure:</p>
  
  <pre><code> typedef struct tosc_message {
      char *format;  // a pointer to the format field
      char *marker;  // the current read head
      char *buffer;  // the original message data (also points to the address)
      uint32_t len;  // length of the buffer data
  } tosc_message;
  </code></pre>
  
  <p>and tosc_parseMessage is:</p>
  
  <pre><code>int tosc_parseMessage(tosc_message *o, char *buffer, const int len) {
    // NOTE(mhroth): if there's a comma in the address, that's weird
    int i = 0;
    while (buffer[i] != '\0') ++i; // find the null-terimated address
    while (buffer[i] != ',') ++i; // find the comma which starts the format string
    if (i &gt;= len) return -1; // error while looking for format string
    // format string is null terminated
    o-&gt;format = buffer + i + 1; // format starts after comma
  
    while (i &lt; len &amp;&amp; buffer[i] != '\0') ++i;
    if (i == len) return -2; // format string not null terminated
  
    i = (i + 4) &amp; ~0x3; // advance to the next multiple of 4 after trailing '\0'
    o-&gt;marker = buffer + i;
  
    o-&gt;buffer = buffer;
    o-&gt;len = len;
  
    return 0;
  }
  </code></pre>
  
  <p>and then i print that out with :</p>
  
  <pre><code>void tosc_printMessage(tosc_message *osc) {
    printf("[%i bytes] %s %s",
        osc-&gt;len, // the number of bytes in the OSC message
        tosc_getAddress(osc), // the OSC address string, e.g. "/button1"
        tosc_getFormat(osc)); // the OSC format string, e.g. "f"
  
    for (int i = 0; osc-&gt;format[i] != '\0'; i++) {
      switch (osc-&gt;format[i]) {
        case 'f': printf(" %g", tosc_getNextFloat(osc)); break;
        case 'd': printf(" %g", tosc_getNextDouble(osc)); break;
        case 'i': printf(" %d", tosc_getNextInt32(osc)); break;
        default: printf(" Unknown format: '%c'", osc-&gt;format[i]); break;
      }
    }
    printf("\n");
  }
  </code></pre>
  
  <p>where my problem is in function:</p>
  
  <pre><code>float tosc_getNextFloat(tosc_message *o) {
    // convert from big-endian (network btye order)
    const uint32_t i = ntohl(*((uint32_t *) o-&gt;marker));
    o-&gt;marker += 4;
    return *((float *) (&amp;i));  &lt;---- this line of code does the error
  }
  </code></pre>
  
  <p>I hope this gives you better view on problem... Im not skilled programmer so i appreciate any help. Full code for this "library" could be found here <a href="https://github.com/mhroth/tinyosc" rel="nofollow noreferrer">https://github.com/mhroth/tinyosc</a> , Im just trying to implement that in my microcontroller</p>