J
Jan Danielsson
Hello all,
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
{
int numAttr;
ATTR attr[1];
}ATTRLIST, *PATTRLIST;
foo()
{
PATTRLIST pal = 0;
...blah...
if(nAttr > 0)
{
pal = malloc(sizeof(ATTRLIST)+(nAttr-1)*sizeof(ATTR))
...blah...
}
}
Now, what I'm worried about is portability. Is using an 1-sized array
like that a bad move? Does C guarantee that structure members are ordered?
Thankful for any advice.
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
{
int numAttr;
ATTR attr[1];
}ATTRLIST, *PATTRLIST;
foo()
{
PATTRLIST pal = 0;
...blah...
if(nAttr > 0)
{
pal = malloc(sizeof(ATTRLIST)+(nAttr-1)*sizeof(ATTR))
...blah...
}
}
Now, what I'm worried about is portability. Is using an 1-sized array
like that a bad move? Does C guarantee that structure members are ordered?
Thankful for any advice.