1

I have code I try to compile on 64 bit MacOS with clang.

#include <cstdint>

int main(){
    static_assert(std::is_same<long, int64_t>::value, "");
}

I did some checks and both long and int64_t are signed integers and sizeof() reports they are 8 byte long.

Both types must be same type, however, when I check with typeid().name() gives result "l" for long and "x" for int64_t.

Whats going on here?

How to rewrite static_assert so it will be portable between 64 bit Linux and 64 bit MacOS?


Update

I think the proposed duplicate is not answering my question.

I checked "stdint.h" on MacOS, and it mention 40, 48 and 56 bit integers too. I believe it is related to that, since pointer distance_type on the MacOS is "long".

Please reopen :)

Community
  • 1
  • 1
Nick
  • 9,962
  • 4
  • 42
  • 80
  • Both types might be able to represent exactly the same range of integer, with the exact same representation, and still be different. The duplicate explains why `int64_t`is likely and alias of `long long` rather than `long` on your 64-bits machine. What exactly do you want to check with your `static_assert`? – Holt May 25 '19 at 11:39
  • static assert checks if two iterators have same difference_type. one is defined by me (int64_t), another is "char *" (long). – Nick May 25 '19 at 11:48
  • Why do you use a different type? Why not use [ptrdiff_t](https://en.cppreference.com/w/cpp/types/ptrdiff_t)? – Holt May 25 '19 at 11:56
  • at some point it was a better idea to use uint64_t. – Nick May 25 '19 at 12:03
  • I did changed it, and I just check it is 8 bit. Thanks. – Nick May 25 '19 at 12:14

0 Answers0