lkml.org 
[lkml]   [2004]   [Jul]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectgcc and aligning
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@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:04    [W:0.033 / U:0.316 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site