compile error in demo program

Discussion in 'C++' started by vfunc@talktalk.net, Jun 1, 2006.

  1. Guest

    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);
    , Jun 1, 2006
    #1
    1. Advertising

  2. 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 -
    Eduardo Grajeda, Jun 1, 2006
    #2
    1. Advertising

  3. Marcus Kwok Guest

    <> 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
    Marcus Kwok, Jun 1, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. F. GEIGER
    Replies:
    9
    Views:
    1,217
    F. GEIGER
    May 3, 2004
  2. Andy Leszczynski

    wxPython demo /Process does not open new demo

    Andy Leszczynski, Feb 18, 2005, in forum: Python
    Replies:
    1
    Views:
    637
    Andy Leszczynski
    Feb 18, 2005
  3. max(01)*

    very simple tkinter demo program

    max(01)*, Apr 9, 2005, in forum: Python
    Replies:
    5
    Views:
    453
    Samantha
    Apr 10, 2005
  4. Replies:
    8
    Views:
    460
    Barry Schwarz
    Jun 2, 2006
  5. Nagaraj
    Replies:
    1
    Views:
    853
    Lionel B
    Mar 1, 2007
Loading...

Share This Page