C Language

Foolproof Statement and Comment Syntax

C is not really a bad language; it's just too often misused. As a language for writing low-level device drivers or operating system kernels, C is superb. It's also a great language for torturing student programmers.

But for business applications or other software above the operating system level, C is a minefield: "Explosive" results await the unwary C programmer's misstep. Here's an example that requires you to pick your way carefully:

 if (xcnt < 2)
 date = x[0];
 time = x[1];

This code appears to guard references to array x by checking the count of its elements first. But a semicolon is missing after the return, so the code really means:

 if (xcnt < 2) {
   return date = x[0];
 time = x[1];

C's "flexibility" lets you freely combine most expressions and statements, such as this assignment expression within a return statement. Unfortunately, this flexibility also means C compilers can't detect many errors caused by simple typos.

by BrainBellupdated