Getting CXType_Int and data size == 4 for uint64_t

I'm writing a simple parser tool using libclang and I noticed
something really odd.

For this simple file as I visit the cursors and call getType on them I
see that A is detected as CXType_Int and 4 bytes of size, but C is
also detected as CXType_Int and 4 bytes of size.

I did not expect this, am I doing something wrong?

#include <stdint.h>

struct TestStruct
{
  uint32_t A;
  const char *B;
  uint64_t C;
};

I'm writing a simple parser tool using libclang and I noticed
something really odd.

For this simple file as I visit the cursors and call getType on them I
see that A is detected as CXType_Int and 4 bytes of size, but C is
also detected as CXType_Int and 4 bytes of size.

I did not expect this, am I doing something wrong?

Your <stdint.h> is probably not designed for your target. They often aren't intended to be "portable".

John.

I would have thought that precisely specifying bit width would be
considered portable? Isn't that the whole point of it? vs long which
is 8 or 4 bytes depending on the OS etc?

I'm not sure where to look or what to modify to get the right size.

I would have thought that precisely specifying bit width would be
considered portable? Isn't that the whole point of it? vs long which
is 8 or 4 bytes depending on the OS etc?

It is absolutely a high-requirement that uint64_t be a 64-bit type, but it's not the
compiler's responsibility to make that happen. The compiler assigns sizes to the
fundamental types, like 'int' and 'long', based on the current target. Types like
'uint64_t' are typedefs, and headers like stdint.h are supposed to define them to
be a type that's known to have the right size for the target. So if stdint.h thinks
'unsigned long' is a 64-bit type and therefore reasonable to typedef 'uint64_t' to,
but the compiler thinks that 'unsigned long' is a 32-bit type, you can get problems
like this.

You should start by checking two things: what clang thinks the current target is and
where it's picking up the system headers. I would guess that one or the other is not
what you expect.

Another possibility is that clang is supposed to be using its compiler-provided headers
on your target, but it can't find them because of how you've built it.

John.