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 32,615 of 33,346   
   fmatthew5876 to All   
   Re: initializing array using another arr   
   25 Oct 12 14:07:48   
   
   82ec33d1   
   From: fmatthew5876@googlemail.com   
      
   > Because in certain cases losing information (array size known at   
   > compile-time) is unacceptable. You'll be surprised how much time   
   > typical C++ program spends scanning memory for zero byte or similar   
   > operations which could be avoided if array length was not lost   
   > somewhere due to array-to-ptr decay (which C++ does so eagerly, that   
   > you can't prevent it even if you wanted to).   
      
   You can prevent decay by making a struct that contains your fixed size   
   array and passing that to functions.   
      
   struct MyArray {   
      char string[32];   
   }   
      
   A normal function that takes an array as a parameter has no way of knowing   
   its size when it is compiled. The user could pass in any kind of array   
   or pointer. If you know the array is always of fixed size and not null   
   (not a pointer), then you can use a struct/class with an array inside.   
      
      
   --   
         [ 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