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,349 of 33,346    |
|    =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to All    |
|    Re: Is there in the C++'s standard a not    |
|    17 May 11 16:50:40    |
   
   62867f87   
   From: daniel.kruegler@googlemail.com   
      
   Am 17.05.2011 13:50, schrieb ioan:   
   >   
   > Hello.   
   >   
   > First, I would like to give a short description on how the information   
   > in this message is structured. I will state my question, then I will   
   > give all the text I know in the C++ specification, to relate with my   
   > question. In the end I give my thoughts on this subject.   
   >   
   > [[The question]]   
   > How many items can there be defined in a C++ array so that the code   
   > containing the C++ array makes a well-defined C++ program considering   
   > that the rest of the C++ program is well-formed?   
   >   
   > [[Text from the C++ specification]]   
   >   
   > 8.3.4 Arrays   
   >   
   > [dcl.array]   
   > In a declaration T D where D has the form   
   > D1 [constant-expressionopt]   
   >   
   > constant-expression shall be an integral constant expression and its   
   > value shall be greater than zero.   
   >   
   >   
   > [[My thoughts on this subject:]]   
   >   
   > // foo.cpp:   
   > int const maxn = 100 * 1000;   
   > int A[maxn];   
   >   
   > int main()   
   > { return 0; }   
   >   
   > // end of foo.cpp:   
   >   
   > Is foo.cpp a well-formed C++ program?   
   >   
   > Here is how I see the possibilities:   
   >   
   > [1]   
   > foo.cpp may be a well-formed program and then any C++ compiler would   
   > build a program from this file. Any machine on which this program (or   
   > some similar program that would actually access the array) would need   
   > to have more than 100*1000 memory locations or the possibility to give   
   > the program (paging memory pages in and out for example).   
   >   
   > [2]   
   > foo.cpp is not well-formed program, but C++ standard guarantees some   
   > smaller array size: 10*1000 for example.   
   >   
   > [3]   
   > C++ does not give a guarantee for the array size.   
   >   
   > I wonder how you see this aspect of the C++ language,   
      
   For [1] there does not exist a strong enough requirement to be binding,   
   [3] is the most defensive assertion that can be given, but there exists   
   at least a good guess for a lower bound of the minimum required lower   
   bound of an array size. I'm not 100% sure in which way [2] is supposed   
   to be read: Are you suggesting that there exists a guarantee that the   
   initially shown program will be ill-formed? This would be surely incorrect.   
      
   In regard to [2] we can use the so-called "implementation quantities" as   
   a criterion. They are only recommendations (so non-binding), but provide   
   at least a rough estimate. The best match is the lower bound for the   
   maximum object size to be 262144. I can only assume that the unit is   
   bytes, which is not explicitly said, but the most reasonable   
   interpretation. To obtain the suggested minimum size we need to devide   
   by sizeof(int), which is often 4, sometimes 1 or 2 bytes as well.   
   Assuming 4 bytes this will give us an estimate of about 65535 elements   
   which is less than 100000.   
      
   Interestingly, C99 provides indeed a normative lower bound requirement   
   for at least one object that at least 65535 bytes can be allocated in a   
   hosted environment, which leads us to a minimum array size of 16383   
   elements assuming size(int) == 4.   
      
   In summary, if at all, you can only determine a good guess for a lower   
   bound of the minimum array size of element type T being equal to   
   65535/sizeof(T).   
      
   HTH & Greetings from Bremen,   
      
   Daniel Krügler   
      
      
   --   
    [ 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