error: 'uint16_t' undeclared? [duplicate]
Asked Answered
E

1

42

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|
Ecclesiastical answered 2/7, 2013 at 21:59 Comment(0)
E
94

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

Early answered 2/7, 2013 at 22:0 Comment(6)
I don't use C much so for me its new.Ecclesiastical
Must be someone using MSVC without access to the headers (since they were added in C99 and MSVC only supports C89), or something.Hygienist
Weirdos. The question is both tagged GCC and says "I'm using GCC" in the body.Early
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.Ecclesiastical
Aside: Browsing through an Intel 32bit to 64bit guide, software.intel.com/sites/default/files/m/d/4/1/d/8/…, I discovered that uint16_t is an architecture defined type for Unix.Kyanite
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.Reclaim

© 2022 - 2024 — McMap. All rights reserved.