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,059 of 33,346    |
|    =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to All    |
|    Re: Modification of trailing null charac    |
|    28 Mar 12 12:13:36    |
   
   f0bfee87   
   From: daniel.kruegler@googlemail.com   
      
   {Please do not overquote -mod/we}   
      
   Am 28.03.2012 19:55, schrieb Nikolay Ivchenkov:   
   > According to N3376 - 21.4.5/2   
   >   
   > reference operator[](size_type pos);   
   >   
   > Returns: *(begin() + pos) if pos< size(). Otherwise, returns a   
   > reference to an object of type charT with value charT(), where   
   > modifying the object leads to undefined behavior.   
   >   
   > If my understanding of this rule is correct, we can't safely assign   
   > zero value to the trailing null character in a string object, even   
   > if the string is non-empty:   
   >   
   > 1)   
   > std::string s;   
   > char&c = s[0]; // well-defined   
   > assert(c == '\0'); // succeeds   
   > c = '\0'; // undefined   
   > 2)   
   > std::string s = "text";   
   > char&c = s[s.size()]; // well-defined   
   > assert(c == '\0'); // succeeds   
   > c = '\0'; // undefined   
      
   This interpretation is correct, yes.   
      
   > and the following implementation of get_window_text_w is not   
   > well-defined:   
   >   
   > #include
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca