There is no 64-bit type in C89

Brief post, but I was porting a C89 project to Visual C++ 6 (don’t ask) when I found something really fun. Turns out “long long“, the type everyone assumes is the 64-bit type in C, is actually a GCC extension. MSVC uses… _int64, a different extension. Great, had to convert a bunch of code. You’ll get this fun error from old MSVC when it sees it:

error C2632: 'long' followed by 'long' is illegal

(Note that MSVC will probably assume your C code is C++, which does mean you get some stuff from C99 for free like single-line comments… but then initializers are different between C and C++, and C++ only added long long in C++11…)

It’s an unfortunate gotcha for those who assume they’re writing standards compliant C89. The reason might be deflated when you have to define your own 64-bit integer with #ifdef. Oh, and let’s not forgot “long long” could mean 72-bit on your 9-bit byte system, of course. That’s why stdint.h exists…. except, oh, C89.

2 thoughts on “There is no 64-bit type in C89

  1. Keith Thompson July 5, 2021 / 3:31 am

    There is no *required* 64-bit integer type in C89/C90. And no version of C requires the existence of an integer type that’s *exactly* 64 bits.

    “long long” is a gcc extension in C89/C90, but an ISO standard type in C99 and later. It’s required to be *at least* 64 bits wide. int64_t, defined in is required to be exactly 64 bits, but if the implementation has no 64-bit integer type it won’t be defined.

    Also, it’s entirely possible for a conforming C89/C90 implementation to make “long” 64 bits (I’ve worked with such compilers), but most don’t.

    As for stdint.h, there are C90-compatible implementation of it, including this one:
    https://www.lysator.liu.se/c/q8/stdint.h

    (Fortunately, most of us don’t need that, but if you do it’s there.)

Leave a Reply

Your email address will not be published. Required fields are marked *