Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Whats the difference between the “unsigned preserving\ and “value preserving\ rules?

difference preserving rules
0
Posted

Whats the difference between the “unsigned preserving\ and “value preserving\ rules?

0

These rules concern the behavior when an unsigned type must be promoted to a “larger” type. Should it be promoted to a larger signed or unsigned type? (To foreshadow the answer, it may depend on whether the larger type is truly larger.) Under the unsigned preserving (also called “sign preserving”) rules, the promoted type is always unsigned. This rule has the virtue of simplicity, but it can lead to surprises (see the first example below). Under the value preserving rules, the conversion depends on the actual sizes of the original and promoted types. If the promoted type is truly larger–which means that it can represent all the values of the original, unsigned type as signed values–then the promoted type is signed. If the two types are actually the same size, then the promoted type is unsigned (as for the unsigned preserving rules). Since the actual sizes of the types are used in making the determination, the results will vary from machine to machine. On some machines, short int

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123