Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Weak typing in C allows type casting memory to different types. Because the internal representation of most types is system dependent, applying operations intended for data of one type to data of a different type will likely yield non-portable code and produce unexpected results.

Non-Compliant Code Example (Integers vs.

...

Floating-Point Numbers)

The following non-compliant code demonstrates the perils of operating on data of incompatible types. An attempt is made to increment an integer type cast to a floating point type, and a floating point cast to an integer type.

...

Code Block
int is 0, float is 0.000000
int is 1065353216, float is 0.000000

Compliant Solution (Integers vs.

...

Floating-Point Numbers)

In this compliant solution, the pointers are assigned to variables of compatible data types.

...