Compiler academic question - why?
-
Why the compiler did not complain about the erroneous ";" ?
if(QP->waitForFinished())
{
text = "QProcess finished";
qDebug() << text;
};wrong ; here !
It's not wrong. Empty statement is a valid C/C++ statement. You can try:
;;;; //this is valid
Also, a very popular beginner mistake is to add a spurious semicolon at the end of a while and wonder why the while "body" is not repeated:
while (i>0); //spurious semi
{
//this is not looped
}Mircea
-
Why the compiler did not complain about the erroneous ";" ?
if(QP->waitForFinished())
{
text = "QProcess finished";
qDebug() << text;
};wrong ; here !
To add to what Mircea has said, you may even include empty blocks e.g.
int main()
{
{}
std::cout << "Hello World!\n";
{}
}compiles without complaint. While that seems rather silly, source code like that might be generated when a pre-processor
#define
is expanded or perhaps if you have some sort of code generator as part of the build process. e.g. something like Oracle Pro*C, or Postgresql ecpg.Keep Calm and Carry On
-
It's not wrong. Empty statement is a valid C/C++ statement. You can try:
;;;; //this is valid
Also, a very popular beginner mistake is to add a spurious semicolon at the end of a while and wonder why the while "body" is not repeated:
while (i>0); //spurious semi
{
//this is not looped
}Mircea
-
Quote:
Also, a very popular beginner mistake
Now, you're calling me 'beginner'. :doh: :laugh: :laugh: :laugh:
"In testa che avete, Signor di Ceprano?" -- Rigoletto
Aren’t we all beginners constantly trying to learn new things? Do you think I saw that error in a book? :laugh:
Mircea