home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 33,270 of 33,346   
   scott to All   
   Variable declaration and initialization    
   13 Jan 14 01:54:03   
   
   From: sdcoonce@googlemail.com   
      
   { Please limit your text to fit within 80 columns, preferably around 70,   
     so that readers don't have to scroll horizontally to read each line.   
     This article has been reformatted manually by the moderator. -mod }   
      
      
   Hello,   
      
   I found code similar to the following in some client's codebase which   
   we had been asked to repair for new compilers, and was curious about   
   why this should compile and (seem to) work.  I was wondering if the use   
   of 'a' before initialization is really undefined behavior or just an   
   specified result.  Also, it seems intuitively to me that 'a' shouldn't   
   yet be in scope, though apparently it is.   
      
   I tried to find relavent paragraphs in the C++ standard but was unable   
   to find anything definitive.  Could someone who's better at reading the   
   standard than myself point me in the right direction?   
      
   //------------------------------------------   
   #include    
      
   using std::cout;   
   using std::endl;   
      
      
      
   int main(int argc, const char** argv) {   
      
      
      double a = a * 2.0;   
      cout << "a = " << a << "\n";   
      
      return 0;   
      
   }   
      
   //--------------------------------------------   
      
   In fact, I was suprised that the compilers (Windows VS2012) doesn't   
   automatically emit a warning for this case. With /Wall, it does --   
   but then there are hundreds of errors in standard header files.   
   I understand why we don't compile with /Wall.   
      
   Thanks,   
   Scott   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca