The Rationale Behind C Containers Banning Incomplete Types
In the world of C programming, containers are essential data structures for organizing and manipulating data. However, one peculiar characteristic of C containers is their aversion to incomplete types. Why is this so?
The answer lies in the historical evolution of C . In the early days, the Standard Template Library (STL) implementations struggled to handle containers with incomplete types. To maintain stability and backward compatibility, the standardization committee made the decision to outright ban such containers in the C standard.
This restriction was particularly effective in preventing recursive data structures. It also ensured that existing STL implementations could continue functioning as intended without introducing any unforeseen issues.
However, the prohibition on incomplete types has also drawn some criticism. It limits certain advanced data structure implementations and would benefit from a revisit in future revisions of the C standard.
While the standard containers remain incomplete-type-averse, library designers like those behind boost::container have taken the initiative to create their own containers that do not impose this restriction. This decision allows for greater versatility and flexibility in C programming.
Update:
With the advent of C 17, certain containers in the Standard C Library have been amended to allow incomplete types. However, this is not a universal change, and the general prohibition remains in place for most containers in the standard.
The above is the detailed content of Why Do C Standard Containers Typically Forbid Incomplete Types?. For more information, please follow other related articles on the PHP Chinese website!