Re: Array in struct




In article <4305b575@xxxxxxxxxxxxxxxxx>, Jan Danielsson <jan.danielsson@xxxxxxxxx> writes:
>
> I'm writing an XML parser, and I'd like to know how portable a
> solution is.
>
> When I pass an STag or EmptyElement tag to the application, I
> (obviously) need to pass the attribute list somehow. I thought about
> storing the list in something like this:
>
> typedef struct _ATTRLIST

Others have already discussed the "struct hack", but note also that
identifiers beginning with an underscore followed by an uppercase
letter are always reserved to the implementation. You cannot
portably use the struct tag "_ATTRLIST" for your own structure.
Similarly, any identifier that begins with an underscore is reserved
at file scope. Best bet: don't begin your identifiers with under-
scores. C90 7.1.3.

(Personally, I don't see why you use both a struct tag and a typedef,
since the struct doesn't contain a pointer to the same struct type.
My preference is to avoid typedef in nearly all situations, and
particularly to not disguise a pointer type using typedef, but those
are questions of style. Also, I avoid identifiers in block capitals;
some like to reserve those for macro names, but I use mixed case for
all identifiers as I've found that reduces the likelihood of name
collisions in the environments where my code is typically compiled.
That too is a style issue, of course.)

--
Michael Wojcik michael.wojcik@xxxxxxxxxxxxxx

It does basically make you look fat and naked - but you see all this stuff.
-- Susan Hallowell, TSA Security Lab Director, on "backscatter" scanners
.



Relevant Pages

  • Re: Problems dereferensing my C structures (custom types)
    ... implementation, at file scope. ... This declaration probably is at file ... _tbl_certificate is not a legal name for that struct. ... (Identifiers beginning with __ or _ and a capital letter are reserved ...
    (comp.lang.c)
  • Re: Question about a struct declaration
    ... Identifiers beginning with _ and a lower-case letter are ... but most struct types (a.o.t. ... namespaces for struct identifiers and for normal ones, so "struct dummy" ...
    (comp.lang.c)
  • Re: problems with ANSI C grammar for yacc
    ... The problem is that structure members inhabit a different name space ... from ordinary identifiers. ... So foo in the typedef is in the fourth name space but foo in the struct ...
    (comp.lang.c)
  • Re: problems with ANSI C grammar for yacc
    ... >>from ordinary identifiers. ... >>So foo in the typedef is in the fourth name space but foo in the struct ... The official ISO 'C' standard says 4 - that is the authority on the ... You can buy a copy of the ISO standard for a recommended £34.95 in the ...
    (comp.lang.c)
  • Re: struct definition...
    ... struct ms inst; ... The syntax for "typedef" is identical to that for ordinary variable ... Typedef-ed identifiers obey normal scoping rules. ...
    (comp.lang.c)