Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > compile error in demo program

Reply
Thread Tools

compile error in demo program

 
 
vfunc@talktalk.net
Guest
Posts: n/a
 
      06-01-2006
I get a compile error at line 285 of this demo
error converting from void* to pollfd*
Do I need to set some compiler flag ?
I did not write this so I'm reluctant to change anything.


251
252 /*
253 * Transfer method - write and wait for room in buffer using
poll
254 */
255
256 static int wait_for_poll(snd_pcm_t *handle, struct pollfd *ufds,
unsigned int count)
257 {
258 unsigned short revents;
259
260 while (1) {
261 poll(ufds, count, -1);
262 snd_pcm_poll_descriptors_revents(handle, ufds,
count, &revents);
263 if (revents & POLLERR)
264 return -EIO;
265 if (revents & POLLOUT)
266 return 0;
267 }
268 }
269
270 static int write_and_poll_loop(snd_pcm_t *handle,
271 signed short *samples,
272 snd_pcm_channel_area_t *areas)
273 {
274 struct pollfd *ufds;
275 double phase = 0;
276 signed short *ptr;
277 int err, count, cptr, init;
278
279 count = snd_pcm_poll_descriptors_count (handle);
280 if (count <= 0) {
281 printf("Invalid poll descriptors count\n");
282 return count;
283 }
284
285 ufds = malloc(sizeof(struct pollfd) * count);

 
Reply With Quote
 
 
 
 
Eduardo Grajeda
Guest
Posts: n/a
 
      06-01-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) escribió:
> I get a compile error at line 285 of this demo
> error converting from void* to pollfd*
> Do I need to set some compiler flag ?
> I did not write this so I'm reluctant to change anything.
>
>
> 251
> 252 /*
> 253 * Transfer method - write and wait for room in buffer using
> poll
> 254 */
> 255
> 256 static int wait_for_poll(snd_pcm_t *handle, struct pollfd *ufds,
> unsigned int count)
> 257 {
> 258 unsigned short revents;
> 259
> 260 while (1) {
> 261 poll(ufds, count, -1);
> 262 snd_pcm_poll_descriptors_revents(handle, ufds,
> count, &revents);
> 263 if (revents & POLLERR)
> 264 return -EIO;
> 265 if (revents & POLLOUT)
> 266 return 0;
> 267 }
> 268 }
> 269
> 270 static int write_and_poll_loop(snd_pcm_t *handle,
> 271 signed short *samples,
> 272 snd_pcm_channel_area_t *areas)
> 273 {
> 274 struct pollfd *ufds;
> 275 double phase = 0;
> 276 signed short *ptr;
> 277 int err, count, cptr, init;
> 278
> 279 count = snd_pcm_poll_descriptors_count (handle);
> 280 if (count <= 0) {
> 281 printf("Invalid poll descriptors count\n");
> 282 return count;
> 283 }
> 284
> 285 ufds = malloc(sizeof(struct pollfd) * count);


It should be:

ufds = (struct pollfd*)malloc(sizeof(struct pollfd) * count);

This code looks like C though, if you happen to need more help you might
wanna try on comp.lang.c instead.

- Eduardo Grajeda -
 
Reply With Quote
 
 
 
 
Marcus Kwok
Guest
Posts: n/a
 
      06-01-2006
(E-Mail Removed) <(E-Mail Removed)> wrote:
> I get a compile error at line 285 of this demo
> error converting from void* to pollfd*
> Do I need to set some compiler flag ?
> I did not write this so I'm reluctant to change anything.
>
> 285 ufds = malloc(sizeof(struct pollfd) * count);


This looks like C, not C++. In C, it is better not to cast the result
of malloc() because this can hide the fact that you forgot to #include
<stdlib.h>. However, in C++, you need to cast the result of malloc()
since C++ doesn't allow the implicit conversion from void* to another
pointer type. In C++, "new" is usually used instead of malloc() since
new is type-safe whereas malloc() is not, and "new" will construct
objects whereas malloc() basically only reserves memory.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to compile the following source code in VC6// I have error inVC++6 but compile ok in GCC fAnSKyer C++ 2 06-07-2009 07:57 AM
cant compile on linux system.cant compile on cant compile onlinux system. Nagaraj C++ 1 03-01-2007 11:18 AM
undefined reference error compiling demo program vfunc@talktalk.net C Programming 8 06-02-2006 12:50 AM
wxPython demo /Process does not open new demo Andy Leszczynski Python 1 02-18-2005 06:03 PM
PyOpenGL demo in wxPython demo crashes F. GEIGER Python 9 05-03-2004 04:43 PM



Advertisments