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,618 of 33,346    |
|    Francis Glassborow to Seungbeom Kim    |
|    Re: initializing array using another arr    |
|    26 Oct 12 09:21:54    |
   
   From: francis.glassborow@btinternet.com   
      
   On 26/10/2012 06:29, Seungbeom Kim wrote:   
   >   
   > On 2012-10-23 14:18, Michael Kilburn wrote:   
   >>   
   >> Is there any way to initialize C array with values from another C   
   >> array? Here is boiled down example:   
   >>   
   >> char const S1[sizeof("ABCD")] = "ABCD";   
   >> char const S2[] = S1; // :-/   
   >>   
   >> code above won't compile (GCC 4.4.3).   
   >   
   > It's a simple matter: initializing an object with the value of   
   > another object with the same type. I wonder why it was made illegal;   
   > otherwise it could have obviated the need for all the workarounds.   
   >   
      
   Yes but that was C. And no half way competent C programmer would write   
   the above code. They would simply have written   
      
   char const * S1 = "ABCD";   
   char const * S2 = S!;   
      
   They might or might not have constrained S1 and S2 to be const pointers.   
      
   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