gcc and aligning

From: Grzegorz Kulewski
Date: Sat Jul 10 2004 - 13:24:20 EST


Hi,

I am trying to experiment with real Linux kernel programming. And I have
this question.

I have:

struct tree_node {
struct tree_node *left, *right;
...
};

struct some1 {
struct tree_node n;
...
};

struct some2 {
struct tree_node n;
...
};


And I want to write universal function that searches tree of structs some1
or some2 (but one kind of struct per one tree). Like this:

struct tree_node *search(struct tree_node *root, struct tree_node *key,
size_t size_of_the_struct);

And in this function I want to compare the _rest_ of some1 or some2 (the
key) against other nodes. But gcc can insert some alignment between n and
the rest of some1 or some2. Can I assume that the alignment fill is the
same in all instances of this struct (for example 0 bytes) and use memcmp
to compare bytes from begin_of_the_struct + sizeof(struct tree_node) to
begin_of_the_struct + size_of_the_struct?

Or is there some better solution?


Thanks,

Grzegorz Kulewski

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/