0

For example, why does this work:

int main(int argc, char **argv) {
    // Code here
    return 0;
}

But not this:

uint16_t main(int argc, char **argv) {
    // Code here
    return 0;
}

Or any other such variation of int?

Techflash
  • 25
  • 1
  • 6
  • 3
    Because that is the spec https://stackoverflow.com/a/4211927/860585 – Rotem Feb 13 '22 at 03:01
  • 1
    Because ’uint16_t` isn’t `int`. – Pete Becker Feb 13 '22 at 03:25
  • The value is returned to the OS, which expects conventionally an *int*. In C++ that must be *int*, but in C you can return whatever fits you (like in assembly), the OS still expects an *int* though. – Déjà vu Feb 13 '22 at 03:44
  • On amd64 platforms that use the sysv ABI (both lp64 and ilp32 variants), all integers up to `int64_t` *happen* to have the same ABI. But this is not true on all platforms. Even on x86, we could imagine an ABI where only the low bits of the register were defined for some integer types (this might be the case; I'm not familiar with other ABIs). – o11c Feb 13 '22 at 03:44
  • 1
    `uint16_t` is not a "variation" of `int`. It is a distinct type. They are not interchangeable. – Peter Feb 13 '22 at 07:29

0 Answers0