Compilers and negative numbers

Recently I was confused by this question . Maybe because I did not read the language specification (this is my mistake, I know).

The C99 standard does not indicate which negative numeric representation should be used by the compiler. I always thought that the only correct way to store negative numbers is with two additions (in most cases).

So, here is my question: do you know any modern compiler that by default implements one addition or sign-value? Can we change the default view with some compiler flag?

What is the easiest way to determine which view is used?

What about the C ++ standard?

+5
source share
3 answers

I think this is not a question of what kind of representation the compiler uses, but rather what the underlying machine uses. The compiler would be very stupid to choose a view that is not supported by the target machine, as this would lead to an overhead load without any advantages.

Some fields of the checksum in the set of IP protocols use one addition, therefore, it is possible that a dedicated "network accelerator" -type CPU: s implements it.

+5
source

twos-complement , , , (. ). C ++ , , , . C ++ .

undefined .

+1

The UNISYS 2200 series , which implements one math supplement, is still in use. You can learn more about this in the questions below.

Exotic architectures that standards committees take care of

Are there any implementations that don't support binary C?

+1
source

All Articles