liveBook · Manning

Implementation defined

As explained in Modern C, Third Edition

Implementation-defined behavior is behavior for which the C implementation chooses among permitted alternatives and documents its choice.

Implementation-defined behavior occurs when the C standard permits alternatives and the implementation chooses and documents one. The choice is valid for that implementation, but code depending on it is not portable. section 5.2

Signedness of char

The base type char may behave like either signed or unsigned, depending on the platform. Consequently, code that relies on the range or signedness of char can behave differently across implementations. section 5.2

Implementation-defined choices appear in several related situations:

  • The C standard constrains, but does not prescribe, the precision of its unpromoted integer types; their properties depend on implementation-defined factors. section 5.2
  • Types such as int and long may have identical value sets while remaining distinct types. section 5.2
  • Converting UINT_MAX to a signed integer type has an implementation-defined result: an implementation may preserve the bit pattern or stop execution. section 15.1.2

Implementation-defined does not mean universally portable. Treat implementation-defined conversions that cannot represent the source value as erroneous, even though each implementation defines its own behavior. section 15.1.2

Table 5.1 Base types according to the four main type classes. Types with a gray background don’t allow for arithmetic; they are promoted before doing arithmetic. Type char is special since it can behave like unsigned or signed, depending on the platform. All types in this table are considered to be distinct types, even if they have the same class and precision.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
ClassSystematic nameOther nameRank
IntegersUnsignedbool_Bool0
unsigned char1
unsigned short2
unsigned intunsigned3
unsigned long4
unsigned long long5
[Un]signedchar1
Signedsigned char1
signed shortshort2
signed intsigned or int3
signed longlong4
signed long longlong long5
Floating pointRealfloat
double
long double
Complexfloat _Complexfloat complex
double _Complexdouble complex
long double _Complexlong double complex

Use the base-type table to compare distinct C types and identify char's implementation-dependent signedness. section 5.2

How Modern C, Third Edition covers it

How deep it goes
Defines implementation-defined behavior and illustrates type ranges, char signedness, and invalid conversions without detailing compiler mechanisms.
Examples
Uses char signedness, equal int and long ranges, and conversion of UINT_MAX to a signed type.
What it assumes
Assumes familiarity with C integer types, signedness, value ranges, and conversions.
What you can do after
Diagnose portability risks by identifying type and conversion behavior that varies among C implementations.
How it connects
Connects implementation-defined behavior with C base types, integer promotions, value ranges, and integer conversions.

Also explained in

Compare how 2 books explain implementation defined →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.