• News
  • Idefisk
  • Tools
  • Tutorials
  • Forum
  • Reviews
  • VoIP Providers
  • Archives
  • Gallery
ZOIPER softphone
AsteriskGuru Archives
Mailing List Archives
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[asterisk-dev] OT: C problems with access to "struct ast_fra

 
   AsteriskGuru Archives Forum Index -> Asterisk-Dev
View previous topic :: View next topic  
Author Message
wirtz at dfn.de
Guest





PostPosted: Sun May 24, 2009 6:42 pm    Post subject: [asterisk-dev] OT: C problems with access to "struct ast_fra

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:

...
member.c:146: error: cannot convert to a pointer type
member.c:146: warning: reading through null pointer (argument 6)
member.c:147: error: cannot convert to a pointer type
...

Hell, what am I doing wrong?

Regards, Holger

_______________________________________________
--Bandwidth and Colocation Provided by http://www.api-digital.com--

asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-dev
Back to top
arkadi.shishlov at gmail.
Guest





PostPosted: Sun May 24, 2009 8:04 pm    Post subject: [asterisk-dev] OT: C problems with access to "struct ast_fra

Holger Wirtz wrote:
Quote:
struct ast_frame {
...
/*! Pointer to actual data */
union { void *ptr; uint32_t uint32; char pad[8]; } data;

use f->data.ptr

_______________________________________________
--Bandwidth and Colocation Provided by http://www.api-digital.com--

asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-dev
Back to top
moises.silva at gmail.com
Guest





PostPosted: Sun May 24, 2009 8:09 pm    Post subject: [asterisk-dev] OT: C problems with access to "struct ast_fra

Quote:
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);
}


You need to read this: http://www.crasseux.com/books/ctutorial/union.html

And use the ptr member of the union.

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.ptr);
}

In the future you may want to take a look at how other code makes use
of frames, is not that hard.

Moy

_______________________________________________
--Bandwidth and Colocation Provided by http://www.api-digital.com--

asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-dev
Back to top
wirtz at dfn.de
Guest





PostPosted: Mon May 25, 2009 5:19 am    Post subject: [asterisk-dev] OT: C problems with access to "struct ast_fra

Arkadi, Moises,

Arkadi Shishlov wrote:
Quote:
Holger Wirtz wrote:
> struct ast_frame {
> ...
> /*! Pointer to actual data */
> union { void *ptr; uint32_t uint32; char pad[8]; } data;

use f->data.ptr


Ahhh! I am such an idiot... ok, I see what I was doing wrong. Sorry for
contacting the list with such a stupid question!

Thanks, Holger


--
##### #### ## ## Holger Wirtz Phone : (+49 30) 884299-40
## ## ## ### ## DFN-Verein Fax : (+49 30) 884299-70
## ## #### ###### Alexanderplatz 1 E-Mail: wirtz@dfn.de
## ## ## ## ### 10178 Berlin
##### ## ## ## GERMANY WWW : http://www.dfn.de
GPG-Fingerprint: ABFA 1F51 DD8D 503C 85DC 0C51 E961 79E2 6685 9BCF

_______________________________________________
--Bandwidth and Colocation Provided by http://www.api-digital.com--

asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-dev
Back to top
tilghman at mail.jeffandt
Guest





PostPosted: Tue May 26, 2009 1:00 pm    Post subject: [asterisk-dev] OT: C problems with access to "struct ast_fra

On Sunday 24 May 2009 14:25:59 Holger Wirtz wrote:
Quote:
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

_______________________________________________
--Bandwidth and Colocation Provided by http://www.api-digital.com--

asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-dev
Back to top
Display posts from previous:   
   AsteriskGuru Archives Forum Index -> Asterisk-Dev All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
contact us at: support@asteriskguru.com - asterisKGuru.com © all rights reserved   |   *asterisk is registered trademark of © Digium™