Incomplete array types (with unspecified size) ?

Discussion in 'C++' started by Timothy Madden, Sep 21, 2010.

  1. Hello

    Why does C++ not allow incomplete array types as C does ?

    Like this:

    struct ArchiveHeader
    {
    size_t iSize;
    int iVerMaj;
    int iVerMin;
    size_t nDataLen;
    unsigned char
    data[]; // unspecified size
    };
    // ArchiveHeader remains an incomplete type,
    // can only be used in a pointer or reference type
     
    Timothy Madden, Sep 21, 2010
    #1
    1. Advertising

  2. On 9/21/2010 11:45 AM, Timothy Madden wrote:
    > Why does C++ not allow incomplete array types as C does ?


    Because it's a different language.

    >[..]


    V
    --
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Sep 21, 2010
    #2
    1. Advertising

  3. Timothy Madden

    James Kanze Guest

    On Sep 21, 4:45 pm, Timothy Madden <> wrote:

    > Why does C++ not allow incomplete array types as C does ?


    > Like this:


    > struct ArchiveHeader
    > {
    > size_t iSize;
    > int iVerMaj;
    > int iVerMin;
    > size_t nDataLen;
    > unsigned char
    > data[]; // unspecified size
    > };


    > // ArchiveHeader remains an incomplete type,
    > // can only be used in a pointer or reference type


    Because C didn't have this "feature" when C++ was being
    designed, and because it causes all sorts of problems when you
    start to use such structures.

    --
    James Kanze
     
    James Kanze, Sep 21, 2010
    #3
  4. Timothy Madden

    Fred Zwarts Guest

    "Timothy Madden" <> wrote in message
    news:4c98d322$0$50443$
    > Hello
    >
    > Why does C++ not allow incomplete array types as C does ?
    >
    > Like this:
    >
    > struct ArchiveHeader
    > {
    > size_t iSize;
    > int iVerMaj;
    > int iVerMin;
    > size_t nDataLen;
    > unsigned char
    > data[]; // unspecified size
    > };
    > // ArchiveHeader remains an incomplete type,
    > // can only be used in a pointer or reference type


    In addition to the other replies: Because C++ has std::vector.
     
    Fred Zwarts, Sep 22, 2010
    #4
  5. Timothy Madden wrote:
    > Hello
    >
    > Why does C++ not allow incomplete array types as C does ?
    >
    > Like this:
    >
    > struct ArchiveHeader
    > {
    > size_t iSize;
    > int iVerMaj;
    > int iVerMin;
    > size_t nDataLen;
    > unsigned char
    > data[]; // unspecified size
    > };
    > // ArchiveHeader remains an incomplete type,
    > // can only be used in a pointer or reference type
    >


    There was a quite lengthy thread recently about structure hack, and that
    seams to be what you are trying to do
     
    Vladimir Jovic, Sep 22, 2010
    #5
  6. On 2010-09-21 09:02, Victor Bazarov wrote:
    > On 9/21/2010 11:45 AM, Timothy Madden wrote:
    >> Why does C++ not allow incomplete array types as C does ?

    >
    > Because it's a different language.


    If it were just a different language, it wouldn't have a design rule
    saying "No gratuitous incompatibilities with C." While it is true that
    C++ is a different language from C, that alone doesn't justify an
    incompatibility. Neither would adopting the feature deprive C++ of its
    identity distinct from C.

    Your answer gives an impression that the C++ committee decided to remove
    or to not add the feature just to be different, which is certainly not true.
    As others have said in this thread, there are better reasons to give.

    --
    Seungbeom Kim
     
    Seungbeom Kim, Sep 23, 2010
    #6
  7. Timothy Madden

    James Kanze Guest

    On Sep 23, 12:22 am, Seungbeom Kim <> wrote:
    > On 2010-09-21 09:02, Victor Bazarov wrote:


    > > On 9/21/2010 11:45 AM, Timothy Madden wrote:
    > >> Why does C++ not allow incomplete array types as C does ?


    > > Because it's a different language.


    > If it were just a different language, it wouldn't have a design rule
    > saying "No gratuitous incompatibilities with C." While it is true that
    > C++ is a different language from C, that alone doesn't justify an
    > incompatibility. Neither would adopting the feature deprive C++ of its
    > identity distinct from C.


    The rule is "as close to C as possible, but no closer".

    > Your answer gives an impression that the C++ committee decided
    > to remove or to not add the feature just to be different,
    > which is certainly not true.


    Sort of. I don't think that the C++ committee actually
    "decided" anything. C added this feature. To add it to C++
    would require a proposal, with a careful study of the impact and
    restrictions (e.g. you probably can't derive from such a beast);
    in such a proposal, remaining compatible with C would certainly
    count as a strong motivation. But as far as I know, no one felt
    the issue important enough to make the effort of writing such
    a proposal. In other words, the committee counts on the efforts
    of volenteer workers, and nobody volenteered.

    --
    James Kanze
     
    James Kanze, Sep 23, 2010
    #7
  8. Fred Zwarts <> wrote:
    > In addition to the other replies: Because C++ has std::vector.


    How many times does this have to be repeated? std::vector is not a
    substitute for "Type array[];". It's a substitute for "Type* array;".
    Different thing (even though the usage syntax is confusingly similar).
     
    Juha Nieminen, Sep 26, 2010
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul F. Dietz

    Question about incomplete array element types

    Paul F. Dietz, Jul 11, 2003, in forum: C Programming
    Replies:
    5
    Views:
    467
    Dan Pop
    Jul 11, 2003
  2. Christopher Benson-Manica

    Pointer to array of unspecified size

    Christopher Benson-Manica, Nov 26, 2003, in forum: C Programming
    Replies:
    14
    Views:
    622
    Dan Pop
    Dec 2, 2003
  3. Bertrand Geston
    Replies:
    1
    Views:
    372
    Bertel Lund Hansen
    Aug 31, 2003
  4. Ulrich Petri
    Replies:
    7
    Views:
    5,291
    Ulrich Petri
    Sep 1, 2003
  5. Grumble

    Pointer to array of unspecified size

    Grumble, Jan 11, 2005, in forum: C Programming
    Replies:
    2
    Views:
    387
Loading...

Share This Page