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 32,550 of 33,346    |
|    Richard Damon to All    |
|    Re: Initializing a shadowing variable wi    |
|    20 Sep 12 11:36:16    |
   
   From: news.x.richarddamon@xoxy.net   
      
   On 9/20/12 12:26 AM, Daniel Krügler wrote:   
   >   
   > I strongly hope CWG 504 gets to be resolved such that the language   
   > would forbid the initialization of a variable with its own value (Note   
   > that valid cases of seemingly self-initialization e.g. a pointer   
   > initialized with the address of the variable should still be allowed).   
   >   
   > HTH & Greetings from Bremen,   
   >   
   > Daniel Krügler   
   >   
   >   
   >   
      
   The problem is that there are cases where it is impossible to tell   
   without looking at the whole program.   
      
   Take the example:   
      
   extern void foo(int& i);   
      
   extern int x;   
      
   void bar(){   
    int x = (foo(x), x);   
   }   
      
      
   Is x inside of bar being self-initialized? Until you know what is inside   
   foo you can not tell. foo might initialize its parameter, or it might   
   not, and the code for foo might not be in the same translation unit.   
      
   It is in the tradition of C/C++ to not require the compiler to dig that   
   hard to figure out if something is wrong. (but it is perfectly ok for   
   the compiler to do what it can to give a warning about this). Because it   
   would be impossible to come up with wording that would disallow all   
   cases, and that reasonably simple wordings will tend to disallow cases   
   that might really be valid and possibly useful, the Standard does its   
   normal thing and requires the programmer to use some minimal care to   
   keep from shooting themselves in their foot.   
      
      
   --   
    [ 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