On Sat, 8 Mar 2008 12:21:09 -0600 (CST), ericshufro@[EMAIL PROTECTED]
wrote:
>Although we have scanned the ANSI-C document, we cannot determine
>whether "prototyping" structures, including a struct's name beyond its
>tag name, is ANSI-C & most likely sup****ted by ANSI-C compliant
>compilers.
>
>
>Similar to prototyping functions, the reason we ask this question is
>to determine whether we can resolve circular definition situations
>that occur when ordering header files which have data type definitions
>each dependent on the other.
>
>
>Example Scenario :
>
>
> #include <types.h>
> #include <header_a.h>
> #include <header_b.h>
>
>
> In 'types.h' :
>
> typedef struct some_tag_name SOME_STRUCT_NAME;
At this point in time, struct some_tag_name is known to the system as
an incomplete type.
>
>
> In 'header_a.h' :
>
> typedef struct some_other_struct {
> ...
> /* Allowed because of prior prototype? : */
> SOME_STRUCT_NAME *psome_struct;
psome_struct is known to be a pointer to some type of struct. The
exact type doesn't matter at this point because the standard requires
all pointers to struct to have the same size and representation.
Therefore, even though the compiler doesn't know very much about the
struct, it does know everything it needs to know in order to properly
create psome_struct.
> ...
> } SOME_OTHER_STRUCT;
>
>
> In 'header_b.h' :
>
> typedef struct some_tag_name {
> ...
> } SOME_STRUCT_NAME;
I don't believe you can do this if some file will #include both
header_a.h and types.h. It would also be unnecessary if the two .h
files are to be used together. Here you would simply complete the
declaration of the structure type with
struct some_tag_name{...};
and omit the typedef and the typedef name.
On the other hand, if some .c files #include types.h and header_a.h
while others #include header_b.h and header_a.h (in both instances
header_a.h must be after the other header), this approach will work
but it is a maintenance nightmare waiting to happen. What is wrong
with moving the complete typedef (as in header_b.h) into types.h?
>
>
>
>If SOME_STRUCT_NAME can be "prototyped" in a header PRIOR to
>'header_a.h', then that structure name can be referenced in other
>header files PRIOR to its actual data type definition.
Omitting the brace enclosed material (and the braces) in a struct
declaration does allow ***pointers to the struct*** to be declared
prior to the complete declaration of the struct, but only pointers.
It's not really a prototype (in the sense that is commonly used for
functions) because it provides no details about the struct.
>
>
>
>
>We have tried this method on one compiler so
>far & it compiles & builds without additional
>warnings or errors. However, we'd like some
>input before we consider using it in released
>software.
>
>If this was a fully ANSI-C compliant method
>to resolve circular data type definitions, it
>would be an immense improvement to our code
>base since it would allow us to remove many
>instances of 'void *' definitions that we
>believe had to be used in order to avoid the
>circular definition problem.
>
>
>
>Thank you for your time & expertise,
Remove del for email
--
comp.lang.c.moderated - moderation address: clcm@[EMAIL PROTECTED]
-- you must
have an appropriate newsgroups line in your header for your mail to be
seen,
or the newsgroup name in square brackets in the subject line. Sorry.


|