Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Compiler academic question - why?

Compiler academic question - why?

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 4 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Why the compiler did not complain about the erroneous ";" ?

    if(QP->waitForFinished())
    {
    text = "QProcess finished";
    qDebug() << text;
    };

         wrong ; here !
    
    Mircea NeacsuM K 2 Replies Last reply
    0
    • L Lost User

      Why the compiler did not complain about the erroneous ";" ?

      if(QP->waitForFinished())
      {
      text = "QProcess finished";
      qDebug() << text;
      };

           wrong ; here !
      
      Mircea NeacsuM Offline
      Mircea NeacsuM Offline
      Mircea Neacsu
      wrote on last edited by
      #2

      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

      CPalliniC 1 Reply Last reply
      0
      • L Lost User

        Why the compiler did not complain about the erroneous ";" ?

        if(QP->waitForFinished())
        {
        text = "QProcess finished";
        qDebug() << text;
        };

             wrong ; here !
        
        K Offline
        K Offline
        k5054
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • Mircea NeacsuM Mircea Neacsu

          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

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          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

          In testa che avete, signor di Ceprano?

          Mircea NeacsuM 1 Reply Last reply
          0
          • CPalliniC CPallini

            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

            Mircea NeacsuM Offline
            Mircea NeacsuM Offline
            Mircea Neacsu
            wrote on last edited by
            #5

            Aren’t we all beginners constantly trying to learn new things? Do you think I saw that error in a book? :laugh:

            Mircea

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups