[ofa-general] Re: opensm/osm_port_t struct definition

Sasha Khapyorsky sashak at voltaire.com
Tue Aug 19 06:39:01 PDT 2008


On 14:30 Tue 19 Aug     , Yevgeny Kliteynik wrote:
> Sasha Khapyorsky wrote:
>> Hi Yevgeny,
>> On 12:23 Tue 19 Aug     , Yevgeny Kliteynik wrote:
>>> I have a general question/concern about osm_port_t:
>>>
>>> typedef struct osm_port {
>>> 	cl_map_item_t map_item;
>>> 	cl_list_item_t list_item;
>>> 	...
>>> } osm_port_t;
>>>
>>> Here and there in the code I see some comments that
>>> map_item and list_item should be first members of the
>>> struct,
>> I cannot find such comment about list_item.
>
> Here are some examples (there are more):
>
> opensm/include/opensm/osm_prefix_route.h
> ----------------------------------------
>
> 	typedef struct {
> 		cl_list_item_t list_item;	/* must be first */
> 		...
> 	} osm_prefix_route_t;

[snip...]

All examples are not about 'struct osm_port' but about some other
structures. How is this related?

> I couldn't find any problem with having list_item not only in the
> beginning of the struct, but I was confused by all these comments
> in the code.

Maybe I'm starting to understand confusion (maybe)...

Example:

struct obj {
	cl_any_item_t item1;
	....
	cl_any_item_t item2;
	...
};

Now you can access this object:

(1) via pointer to item1:

	obj_ptr = (struct obj *)any_item1_ptr;

(2) via pointer to item2:

	obj_ptr = cl_item_obj(any_item2_ptr, obj_ptr, item2);

[ cl_item_obj() is:

#define cl_item_obj(item_ptr, obj_ptr, item_field) (typeof(obj_ptr)) \
        ((void *)item_ptr - (unsigned long)&((typeof(obj_ptr))0)->item_field)

]


Obviously for case (1) 'item1' must be first field in a structure.

> So I guess that only cl_map_item_t has to be first in the struct.

No, it is not related to item type, see above.

Sasha



More information about the general mailing list