Monday, February 21, 2011

C syntax, and spurious semicolons

I've been assisting a colleague with their C code, and he has
learned to add semicolons at the end of statements too well. His
current favourite mistake is to write
if (expression == value);
{
do_something();
};
I frequently miss the trailing semicolon on the first line. So I
was wondering if it would make sense to modify the C syntax file to
highlight
if (expr);
such that the semicolon shows up as an error. Clearly it is a legal
null statement, and so is syntactically correct. But if one only
wanted the expr for its side effects, one would not need to put it
in an if. To do this because one is only using the else part is
poor communication with other programmers.

Is there a good reason not to change the syntax file? Otherwise,
can anyone suggest a patch: my skills in this area are suboptimal,
as I don't change syntax files very often.
Thank you
Hugh

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: