From: dax_uktc@abv.bg   
      
   "Pete Becker" wrote:   
   > On 2011-12-12 22:49:28 +0000, gaoqiang said:   
   >   
   >> c99 support flexable array, which means a zero-length array as the   
   >> last member of a struct.   
   >>   
   >> the implementation of g++ also supports it. Howevery, question is :   
   >> in an object, virtual function   
   >>   
   >> table can reside in any place of the object, how can a flexable array   
   >> work properly ?   
   >   
   > Ask the GCC folks. Flexible arrays are not part of standard C++.   
   >   
      
   In spite of flexible arrays not being part of the C++ standards, they still   
   can easily be emulated. Is this a good programming practice or not, is not a   
   relevant point as far as every single concept, paradigm or idiom, which can   
   be supported by the (standard) language has its own right of existence. And   
   in fact, it surely is used occasionally by someone somewhere. So it is well   
   worth to discuss on the topic.   
      
   >> [...] how can a flexable array   
   >> work properly ?   
      
   It is not only the virtual function which could impose an obstacle for a   
   flexible array to work in the way it is intended to. It would be interesting   
   to see at the cost of what the flexible array support in g++ is. I doubt it   
   could work properly under all possible, or at least reasonable,   
   circumstances.   
      
   Although a C program's trick is sometimes a C++ program's trap (by Stanley   
   Lippman), could C++ flexible array workaround, that is using single-element   
   array at the end of a struct as a means of accessing dynamically allocated   
   variable-sized array, work properly? No, at least not until the class used   
   to accommodate the array is deliberately declared and used with a sense of   
   modesty: single member access specifier throughout the declaration, no   
   inheritance (using it both as a derivate or as a base), no virtual   
   functions. Otherwise, it simply cannot be guaranteed (in a standard   
   compliant and thus portable C++ code) that such a trick would work   
   unconditionally. This is because the order of the class object's data   
   members is not defined in the standard in case some of the above assumptions   
   is not fulfiled.   
      
   See "The Politically Correct Struct" section of Lippman's "Inside the C++   
   Object Model" book for a detailed discussion of the proper usage and   
   applicability of a C struct in C++.   
      
   Regards,   
    Yordan   
      
      
   --   
    [ 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)   
|