Hi Mathias,

On Mar 1, 2011, at 8:21 AM, Mathias Wilhelm wrote:

> Hi Quincey,
> Quincey Koziol wrote:
>>> I am using compound data types with vlen strings and integers. The struct 
>>> containing the strings and integers also contains a couple of methods, 
>>> which prevents me from using the HOFFSET macro, so I used sizeof() and/or 
>>> the getSize() method from the H5 data types to determine the offset of the 
>>> components. This works under my personal 32-bit system, but ends with a 
>>> segmentation fault under a 64-bit system.
>>> I found out that the offset determined by HOFFSET is different from the 
>>> sizeof() and getSize() methods. I avoided this problem by inserting the int 
>>> as the last element.
>>> Is this a general problem/issue or due wrong usage?
>>      You should use HOFFSET for inserting your fields into the compound 
>> datatype.  The compiler may insert padding before/after fields in the struct 
>> and that information is not reflected in the value returned from getSize().
> I would like to use HOFFSET, but since my structs have several methods my 
> compiler gives:
> 
> x.cpp:301: warning: invalid access to non-static data member ‘main1(int, 
> char**)::Test::id’  of NULL object
> x.cpp:301: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
> 
> because they are non-PODs.
> 
> I just found a solution for it. Is this a proper way to do it?
> 
> struct AData {//contains only variables
>       //variables
>       int acc;
>       char* id;
> };
> 
> struct A : AData { //contains only functions
>       //some functions
> }
> 
> Using the HOFFSET(AData, id) macro compiles now without warnings and can be 
> used in the insertMember function of CompType.

        Looks OK to me, but I'm far from enough of a C++ expert to comment 
about the style.  :-)  You could also just use the offsetof() macro directly, 
if that works better.

        Quincey

> FYI:
> My compound data structure is quite complex and consists of several nested 
> VLEN data types, including strings and other VLEN-data as well as atomic 
> types. I need those functions to convert data structures from other API's to 
> H5 compound data types, but also for memory management.
> 
> ~Mathias
> 
> _______________________________________________
> Hdf-forum is for HDF software users discussion.
> [email protected]
> http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org


_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

Reply via email to