0a405bce   
   From: daniel@me.invalid   
      
   In article   
   ,   
   Vipin wrote:   
   > cout << "Partial Array Size : " << sizeof (int [])(&(Data[5]))/   
   > sizeof Data[5] << endl; // I know it is an error but would like to   
   > know why ??   
      
   Because it's nonsense?   
      
   Seriously: You are trying to cast the address of the sixth element of   
   the array to type "int []", which denotes an integer array of   
   unspecified bounds ... if the bounds are unspecified how is the   
   compiler supposed to know how big it is?   
      
   It can't, so you get an error.   
      
   .. but what are you actually trying to compute? It looks as though   
   you're trying to count the number of elements in the array from the   
   sixth (Data[5]) to the end ... wouldn't it be easier to compute the   
   whole length (as you have done) and subtract 5?   
      
   If your question is more general -- you have some pointer p that you   
   know points to an element of an array and you want to know how many   
   elements follow p in that array -- you can do something like:   
      
    cout << "Partial Array Size : "   
    << (sizeof Data - (p - &Data[0])) / sizeof Data[0]   
    << endl;   
      
   Better, though, to work with subscripts rather than addresses, and   
   avoid pointer-fu.   
      
   --   
   Regards,   
    Daniel.   
   [Lest there be any confusion I am NOT the Boost maintainer of the same   
   name]   
      
      
    [ 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)   
|