Visual studio 2008 isn't catching syntax errors. for example: Tpc_feed(void);
compiles fine.
this: Tpc_feed(void);;;;;;;
compiles fine, but this Tpc_feed(void)
catches an error. Are the extra semi-colons not syntax errors? I'm on Windows 7 32 bit and VS C++ 2008
views:
40answers:
3Technically, it's a syntax error, but most compilers allow it anyway. GCC even allows it by default unless you compile with -pedantic
.
In any case, it's against the standard so you should get rid of the extras.
Without a return type, none of them should compile as C++. Assuming a return type is added, the extra semicolons are allowed on member function declarations, but if the declarations are outside a class/struct they're prohibited.
I don't believe VC++ has a flag to force them to be flagged as errors.
Edit: Actually (going back and re-checking things), an unnecessary semi-colon is allowed following a member function definition, but I think you're right, and it's not allowed following a member function declaration.
As others have already said, it's not a valid C++. The reason why many compilers support it anyway is that it makes creating macros a bit easier/more intuitive, consider this:
// Declares a function, and because the semicolon belongs to the declaration, the macro adds it
#define MY_FUNCTION_DECL(returnType, arguments) returnType myFunction arguments;
// Calling macros looks like functions, the semicolon looks natural
MY_FUNCTION_DECL(void, (int, int, int)); // There are two semicolons now
This example is somewhat weird as I made it up right now but it should represent the idea behind accepting more semicolons as valid.