0

I am trying to learn about integer representations in c and I am having a lot of difficulty understand the fact that some operations are undefined meaning they are inconsistent among systems. I find a lot of sources claiming to teach about how these things work sometimes slip in things that are specific to the architecture they are coding for.

When I am coding I intend never to rely on undefined behaviors that happen to work a certain way on most processors.

What is the definitive truth of what happens in c (across all systems) when things like truncation, extension, comparison are done and when unsigned and signed types are included in casting and arithmetic. Which of these operations have a defined behavior across all systems?

J.Doe
  • 1,502
  • 13
  • 47
  • And it may depend on the standard version. Some operations where undefined in older version and become defined later. Now, undefined operation are rather the exception. Most of them are clearly defined, and you should probably ask questions about the problematic case you encountered or refer to the standard (or may be check if there are lists of known problematic cases which would probably be smaller than a list of well defined behaviors). – Camion Jan 13 '18 at 04:22

1 Answers1

2

The definitive truth is the C standard. Links to versions of it are in this answer.

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312