Deep dive ยท the built-in atoms

Elementary Types

BOOL, the integer family, REAL/LREAL, STRING and TIME โ€” the bricks everything else is built from. Each has a size, a range, and a trap. The nastiest: pick a type too small and 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 doesn't error โ€” it wraps back around to its minimum. This bug ships in real machines. 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 โ€” REAL's rounding adds 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 or fieldbus layout matters.

๐Ÿ”ค 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 early.

๐Ÿ” Convert deliberately. Sysmac is strongly typed โ€” use INT_TO_REAL etc. on purpose, and watch 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?