I am currently trying to persuade a twenty-year-old assembler source to compile without warnings under GCC for 64-bit linux, and while I thank the original writer (it's available under GPL) for his work, I can't say the same for his style!
.h files? We've heard of them, but we don't use them, so it's very sensitive to the order in which the files are compiled. But there is no clue as to what the order should be... and it shouldn't matter.
How big is an int? I dunno... there's nothing in the code to indicate whether it's built on an 8, 16, 32 architecture. I can only vaguely guess that it probably wasn't 64 bits.
Magic numbers? They're really the only sort to use.
Externed variables? The only ones we've got.
Bizarre style? Obviously it's personal choice, but if only we all used the very sensible Allman style, and not one that looks like this:
if (Find_Symbol(label) != UNKNOWN) { error_text = "Redefined label"; error_flag = TRUE; } else Add_Symbol(label, Expression_Analyzer(operand));
Note the vertical spacing - there are loads of single-statement if and while statements, which usually (but not always!) have an empty line either side of the statement. He was also fond of single statements, without {} delimiters, that might have multiple nested switch, while or if statements within them. Trying to follow the flow is, um, challenging.
Can we guess what's wrong with this?
*text = NULL;
We won't even discuss the oddball things like using non-standard library functions (strlwr() anyone?). As for returning from the middle of a case statement, not even bothering with a break, bah! And comments? Comments are for wimps! The code is self-documenting, obviously!
Sorry... I just needed a rant. But there is a serious point: if we all try and use standard C and not 'clever' coding; if we try and follow things like MISRA guides; if we think about future maintenance of the code... we might make life a ittle easier for all of us.
Neil
p.s. yes, I know - standards have changed over the years. But it's been obvious since the 80s that integer sizes would change with time; there's a good reason for stdint.h.