38

I have the code

#include <emmintrin.h>
#include <stdio.h>

void print128_num(__m128i var)
{
    uint16_t *val = (uint16_t*) &var;
    printf("Numerical: %i %i %i %i %i %i %i %i \n",
           val[0], val[1], val[2], val[3], val[4], val[5],
           val[6], val[7]);
}
int main(void)
{
    __m128i a = _mm_set_epi32(4, 3, 2, 1);
    __m128i b = _mm_set_epi32(7, 6, 5, 4);
    __m128i c = _mm_add_epi32(a, b);

    print128_num(c);

    return 0;
}

and I'm getting an error where uint16_t isn't declared. I'm using GCC with MINGW.

Heres the complete error.

||In function 'print128_num':|
|6|error: 'uint16_t' undeclared (first use in this function)|
|6|error: (Each undeclared identifier is reported only once|
|6|error: for each function it appears in.)|
|6|error: 'val' undeclared (first use in this function)|
|6|error: expected expression before ')' token|
pandoragami
  • 5,387
  • 15
  • 68
  • 116

1 Answers1

85

You need to include stdint.h or inttypes.h to get uint16_t.

Carl Norum
  • 219,201
  • 40
  • 422
  • 469
  • I don't use C much so for me its new. – pandoragami Jul 02 '13 at 22:06
  • 1
    Must be someone using MSVC without access to the headers (since they were added in C99 and MSVC only supports C89), or something. – Jonathan Leffler Jul 02 '13 at 22:46
  • 2
    Weirdos. The question is both tagged GCC and says "I'm using GCC" in the body. – Carl Norum Jul 02 '13 at 22:48
  • Yeah I know. I have no idea why the downvote either. I tried finding the answer to this using google and all I got were a bunch of Linux related threads telling people to use sudo to install the core linux utils. Someone also wanted to close the thread too. Its the only one around like it. – pandoragami Jul 02 '13 at 22:53
  • Aside: Browsing through an Intel 32bit to 64bit guide, https://software.intel.com/sites/default/files/m/d/4/1/d/8/17969_codeclean_r02.pdf, I discovered that uint16_t is an architecture defined type for Unix. – Dale Jun 01 '19 at 01:45
  • 3
    I ran into this same issue. Another developer was using Visual Studio and I'm using mingw. Couldn't compile his latest push. This was the reason. adding `#include stdint.h` fixed it. – Metric Crapton Apr 27 '20 at 16:53