1

GCC's predefined macro includes __INT8_MAX__ but not __INT8_MIN__.

INT8_MIN is defined in stdint.h with (-__INT8_MAX - 1).

Does GCC assume that the system is in two's complement? I think (INT8_MAX +1) is a better way to define INT8_MIN since it'll work in both 1's complement system and 2's comlement system, and the best is compiler-provided __INT8_MIN__.

Why doesn't gcc provide __INT8_MIN__?

I don't actually have any system not using two's complement so I don't get any trouble using it but I'm just curious.

Inbae Jeong
  • 4,053
  • 25
  • 38
  • 2
    Why does it matter what standard library implementations use internally? That's none of your business. Use the [standard macros](http://en.cppreference.com/w/c/types/limits) and be done with it? Don't spell out anything that contains two consecutive underscores. – Kerrek SB Apr 05 '15 at 15:49
  • 1
    If you're in C++ use [std::numeric_limits](http://blog.hostilefork.com/modern-cpp-or-modern-art/). – HostileFork says dont trust SE Apr 05 '15 at 15:50
  • @KerrekSB Because I'm writing the standard header for my kernel :) – Inbae Jeong Apr 05 '15 at 15:53
  • @kukyakya: I'm not sure how that matters. The free-standing environment guaranteed by the C++ standard covers type range limits (Table 16); no need to roll your own. – Kerrek SB Apr 05 '15 at 16:02
  • @KerrekSB libstdc++'s `cstdint` includes `stdint.h`, which is not part of gcc but libc. There is `stdint.h` in libstdc++, but it actually `#include_next `. I'm writing a self-C++-hosted kernel so I think I have no other way but to roll my own. – Inbae Jeong Apr 05 '15 at 16:09
  • 1
    __INT8_MAX__+1 is a bad idea since overflow is not defined for signed integers. – Otomo Apr 05 '15 at 19:07
  • 2
    Yes, gcc assumes 2's complement. – Marc Glisse Apr 05 '15 at 19:48
  • @Otomo: While that's true from a Standards perspective, it's irrelevant to the GCC/libc boundary because according to the Standard both are part of the same implementation. And it's no problem that one part of the implementation makes assumptions about another part. – MSalters Jul 25 '16 at 13:22

0 Answers0