Deep dive · the built-in atoms

Elementary types

BOOL, the integer family, REAL/LREAL, STRING and TIME are the bricks everything else is built from. Each one has a size, a range and a trap of its own. The worst trap is a type that's too small, because then your counter silently wraps.

🔢 integer overflowREAL vs LREAL
01 · Silent overflow

Count past the edge

Pick an integer type, then keep adding. When you pass its maximum it raises no error and wraps back around to its minimum. This bug ships in real machines, so watch for the flip.

0
02 · The other atoms

Pick the right size, the right precision

🎚️ REAL vs LREAL. REAL is 32-bit (~7 digits); LREAL is 64-bit (~15 digits). For accumulating position or money over millions of cycles, use LREAL, because REAL's rounding errors add up.

🔣 BOOL & bit-packing. A BOOL is one bit of meaning but the controller may store it in a byte/word. Pack flags into a WORD when space is tight or a fieldbus layout calls for it.

🔤 STRING & literals. Strings have a declared max length; TIME literals like T#1s500ms and dates have their own syntax. Mix them up and the compiler complains at build time, before anything runs.

🔁 Convert deliberately. Sysmac is strongly typed, so call INT_TO_REAL and its relatives on purpose, and watch for truncation when going from a wide type to a narrow one.

03 · Check yourself

One quick question

A USINT holds 255. Your code does count := count + 1. What's the new value?