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 31,583 of 33,346   
   Francis Glassborow to Nikolay Ivchenkov   
   Re: Can an arbitrary continuous sequence   
   24 Oct 11 09:48:51   
   
   0c26010a   
   From: francis.glassborow@btinternet.com   
      
   On 24/10/2011 13:18, Nikolay Ivchenkov wrote:   
   > On 23 Oct, 01:20, Edward Diener  wrote:   
   >> On 10/16/2011 9:21 AM, Nikolay Ivchenkov wrote:   
   >>   
   >>> Consider the following example:   
   >>   
   >>>      #include   
   >>>      #include   
   >>>      #include   
   >>   
   >>>      int main()   
   >>>      {   
   >>>          std::vector   vec =   
   >>>              { "0|0", "0|1", "1|0", "1|1" };   
   >>>          std::string (*arr)[2] =   
   >>>              static_cast((void *)vec.data());   
   >>   
   >>>          std::cout<<   arr[1][1]<<   std::endl;   
   >>>      }   
   >>   
   >>> Are the results of the explicit type conversion (performed by   
   >>> static_cast) and of the implicit array-to-pointer conversion well-   
   >>> defined here?   
   >>   
   >> I think the word is "contiguous" sequence, not "continuous" sequence,   
   >   
   > English isn't my native language and I don't feel a difference between   
   > these two words.   
      
   That is understandable. Contiguous is used about discrete objects to   
   indicate that there is no space between them. Continuous Is a property   
   of a single object and implies that it can be broken apart anywhere   
   rather than just at discrete points.   
      
   1,2,3,4,5 is a contiguous sequence of integers.   
   The interval from [1.0, 5.0] is continuous in mathematics but not for   
   floats in computing where it is everywhere discontinuous because there   
   is an infinite set of values between each contiguous float.   
      
   However I can appreciate that both words might get translated to the   
   same word in another language and then mathematics would need to invent   
   a new word for mathematical continuity.   
      
   >   
   >> and since a std::vector is a "contiguous" sequence, you should be fine   
   >> in your code.   
   >   
   > Can you prove that?   
      
   I know that this was discussed several times by WG21 during the last   
   decade. It was certainly intended that the elements of a vector be   
   located in a contiguous sequence and I am pretty sure that words were   
   eventually found for the Standard to require that   
   >   
   > On 24 Oct, 01:12, Francis Glassborow   
   >   wrote:   
   >> On 22/10/2011 22:20, Edward Diener wrote:   
   >>   
   >> I am not entirely sure what the OP meant but I think he was meaning   
   > something like:   
   >>   
   >> int i, j, k;   
   >   
   > No, I didn't mean that. I'm not so naive :-)   
   >   
   >   
      
   Sorry, but as, AFAIK, the Standard requires that the data for a   
   std::vector be stored in an array I was trying to think of what other   
   case might lead to the question.   
      
   Note that i can be treated as an array of 1 element and this led to   
   considerable discussion about how to deal with the case of 1 beyond the   
   end of an array.   
      
   We also need to consider this code in C++   
      
   int i_array[10];   
   int & i{i_array[0]};   
   i = 0;   
   i[1] = 1; // well defined or undefined behaviour?   
      
   Francis   
      
      
   --   
         [ 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