compile error in demo program

V

vfunc

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);
 
E

Eduardo Grajeda

(e-mail address 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 -
 
M

Marcus Kwok

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top