liveBook · Manning

Implementation defined

As explained in Modern C

Implementation-defined behavior is C behavior for which an implementation must choose and document one permitted alternative.

Consider a union that stores 0xAABBCCDD as an unsigned value and exposes the same storage as an array of unsigned char. Printing the bytes may produce 0xDD, 0xCC, 0xBB, 0xAA—or the reverse order—depending on the platform. section 12.2

This is implementation-defined behavior: the C standard permits alternatives, and the implementation chooses one. The in-memory order of representation digits for an arithmetic type is implementation defined. Low-order digits first is little-endian; high-order digits first is big-endian. section 12.2

Other platform choices appear in basic types:

  • The precision of C’s unpromoted integer types is constrained but not prescribed, so it depends on implementation-defined factors. section 5.2
  • The type char may be signed or unsigned depending on the platform. section 5.2
  • Assuming eight-bit unsigned char values and hexadecimal byte formatting also relies on implementation-defined properties: CHAR_BIT equal to 8 and UCHAR_MAX equal to 255. section 12.2

Inspecting integer representation

A union containing unsigned val and unsigned char bytes[sizeof(unsigned)] can print the stored value and each byte. On a little-endian implementation, 0xAABBCCDD appears as DD, CC, BB, AA. The result is useful for observing the implementation, not for assuming a portable byte order.

How Modern C covers it

How deep it goes
Demonstrates integer byte order and character-width assumptions, while deferring representation details for other base types.
Examples
Uses a union, hexadecimal integer 0xAABBCCDD, byte-printing code, and little-endian output as concrete examples.
What you can do after
Evaluate/understand which C type and representation observations are portable and which depend on the implementation.
How it connects
Connects integer types, object representation, endianness, char signedness, CHAR_BIT, and UCHAR_MAX.

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. The section links point to the parts of the book it draws on.