You're viewing a comment by Fraz and its responses.

Fraz Permalink
March 26, 2015, 16:02

It is an error to assume that arithmetic in C is 2's complement. It may be, it may be some of the time depending on optimizations done by the compiler. It is not part of the language specification, the compiler is free to do as it chooses. It is part of a larger problem with C where there is a twilight zone of undefined behavior. The Linux core is written correctly according to the C specifications. Most other C code is not, including common Linux tools. It is a simple language, people assume they know it well because they have years of hands on experience. It is an old language with assumptions from the 1970's. If you fail to read and obey the actual specifications which are rather restrictive your code will exhibit undefined behavior with no warnings from the compiler.

Comment Responses

Nathan Myers Permalink
May 11, 2018, 05:09

In C++2020, all integer types will be guaranteed to be two's complement.

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "server_143": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.