[asterisk-dev] OT: C problems with access to "struct ast_frame.data" member
Tilghman Lesher
tilghman at mail.jeffandtilghman.com
Mon May 25 23:07:07 CDT 2009
On Sunday 24 May 2009 14:25:59 Holger Wirtz wrote:
> Hi all,
>
> sorry for this OT message but since my last Debian update I have some
> trouble to access the data member of the structast_frame:
>
> struct ast_frame {
> ...
> /*! Pointer to actual data */
> union { void *ptr; uint32_t uint32; char pad[8]; } data;
> ...
> }
>
> Before the update I used something like that:
>
> struct ast_frame *f=NULL;
> f=ast_read(chan);
> if(f->frametype==AST_FRAME_TEXT) {
> ast_log(AST_CONF_DEBUG,"Text: %s\n",f->data);
> }
>
> Now I get the following error (with gcc version 4.3.3 (Debian 4.3.3-10))
>
> $ cc -I../asterisk/include -I/usr/lib/glib-2.0/include
> -I/usr/include/glib-2.0 -Wall -c member.c -o member.o
> member.c: In function 'member_exec':
> member.c:146: warning: format '%s' expects type 'char *', but argument 6
> has type 'union <anonymous>'
>
> I tried to cast f->data with (char*)... but this won't work, too:
Right, so this change was to allow you to access the element as multiple
types, without needing to cast, but you need to add an extra argument onto
the end to get this. So change your invocation of f->data to f->data.ptr
(since you want a pointer). You could also use f->data.uint32, if you wanted
an integer type.
--
Tilghman
More information about the asterisk-dev
mailing list