Array of structs
John (J5) Palmieri
johnp at redhat.com
Thu Feb 9 10:18:55 PST 2006
On Thu, 2006-02-09 at 13:07 -0500, Rafa Marin Lopez wrote:
> Hi all
>
> I am trying to create an array of structs (C binding). Each struct has
> two strings and an integer
>
> I have
>
> const char array_sig[] = DBUS_STRUCT_BEGIN_CHAR_AS_STRING\
> DBUS_TYPE_STRING_AS_STRING\
> DBUS_TYPE_STRING_AS_STRING\
> DBUS_TYPE_UINT32_AS_STRING\
> DBUS_STRUCT_END_CHAR_AS_STRING;
>
> char
> string2[]="0000000011111111222222223333333300000000111111112222222233333333";
> char string1[]="004040404040";
> dbus_uint32_t value = 100;
>
> However I obtained a segmentation fault in the second line . what 's
> wrong here?
Common mistake. Pointers to static arrays and pointer to pointers are
two different beasts. What you need to do is create an intermediate
pointer:
char *pstring1;
pstring1 = string1;
And then when you pass it to the API you would pass &pstring1. This is
because in C:
&string1 == &string1[0] == string1[];
&pstring1 != pstring1[0];
--
John (J5) Palmieri <johnp at redhat.com>
More information about the dbus
mailing list