Msvc void* error?

Hey guys,
I’m having a little bit of trouble. Under gcc the following code
compiles correctly:

static void draw_starfield(void) {
int i;

for (i = 0; i < NUM_STAR; i++) {
	*(Uint16 *)(backbuffer->pixels + (int)starfield[i].y *

backbuffer->pitch + (int)starfield[i].x *
backbuffer->format->BytesPerPixel) = starfield[i].color;
}
}

MSVC, however, complains twice on this line:

h:\epiar\0.2.x\src\system\video\video.c(777) : error C2036: ‘void *’ :
unknown size
h:\epiar\0.2.x\src\system\video\video.c(777) : error C2036: ‘void *’ :
unknown size

w/ the same error. Does anybody know what that error means and how I can
go about fixing it?

– chris (@Christopher_Thielen)

static void draw_starfield(void) {
int i;

for (i = 0; i < NUM_STAR; i++) {
*(Uint16 *)(backbuffer->pixels + (int)starfield[i].y *
backbuffer->pitch + (int)starfield[i].x *
backbuffer->format->BytesPerPixel) = starfield[i].color;
}
}

MSVC, however, complains twice on this line:

h:\epiar\0.2.x\src\system\video\video.c(777) : error C2036: ‘void *’ :
unknown size
h:\epiar\0.2.x\src\system\video\video.c(777) : error C2036: ‘void *’ :
unknown size

w/ the same error. Does anybody know what that error means and how I can
go about fixing it?

You need to cast backbuffer->pixls to something other than “void *”. You
have this:

*(Uint16 *)(backbuffer->pixels + (int)starfield[i].y *

It should be:

*(Uint16 *)((Uint16 *) backbuffer->pixels + (int)starfield[i].y *

That is if it’s a 16bpp backbuffer you’re working with. Adjust the UINt16

  • cast of backbuffer->pixels according to the bit depth you’re using.

Of course, this is just a basic C question…

–>Neil-------------------------------------------------------------------------------
Neil Bradley What are burger lovers saying
Synthcom Systems, Inc. about the new BK Back Porch Griller?
ICQ #29402898 “It tastes like it came off the back porch.” - Me

static void draw_starfield(void) {
int i;

for (i = 0; i < NUM_STAR; i++) {
*(Uint16 *)(backbuffer->pixels + (int)starfield[i].y *
backbuffer->pitch + (int)starfield[i].x *
backbuffer->format->BytesPerPixel) = starfield[i].color;
}
}

Ignore my last message.

Why are you using the BytesPerPixel addition? If you know your backbuffer
is 16bpp just do this:

*(((Uint16 *)backbuffer->pixels) +
   (starfield[i].y * backbuffer->pitch) + starfield[i].x) =
	starfield[i].color;

In order:

  • Cast your backbuffer->pixels (it’s of void * and you can’t do pointer
    arithmetic on a void *) to UINT16 * (16bpp per pixel)
  • Multiply the Y coordinate times the buffer’s pitch to align it to the
    proper memory row
  • Add X to it to get the proper X coordinate
  • Assign the starfield color to it

Also, use more parenthesis and don’t rely on operator precedence. It lets
your reader know exactly what you intended. My rule of thumb - if you have
to get a reference to remember the precedence, you need parenthesis.

–>Neil-------------------------------------------------------------------------------
Neil Bradley What are burger lovers saying
Synthcom Systems, Inc. about the new BK Back Porch Griller?
ICQ #29402898 “It tastes like it came off the back porch.” - Me

Chris Thielen wrote:

Hey guys,
I’m having a little bit of trouble. Under gcc the following code
compiles correctly:

No, it compiles it incorrectly, because the code is not legal C[++].
Pointer arithmetic is not defined for type ‘void *’. Do one of the
following intead:

*(Uint16 *)((char *)backbuffer->pixels + (int)starfield[i].y *
backbuffer->pitch + (int)starfield[i].x *
backbuffer->format->BytesPerPixel) = starfield[i].color;

or (preferred):

*((Uint16 *)backbuffer->pixels + (int)starfield[i].y *
backbuffer->pitch / 2 + (int)starfield[i].x) = starfield[i].color;

Both assume that ‘BytesPerPixel’ is 2.–
Rainer Deyke | root at rainerdeyke.com | http://rainerdeyke.com

I wish to use SDL_Mixer in my program for mp3 playback, but so far I’ve been
unsuccessful getting it to work. Right now I’m just trying to get the playmus
program that comes with the tarball to play an mp3. I figure if I can’t get
this to work I have no hope of getting it to work in my program. I am using
Mandrake Linux 8.2, with SDL_Mixer 1.2.4 and SDL 1.2.4

For smpeg I have libsmpeg0.4-0.4.4-10mdk, as well as the devel rpm, installed.
The SDL_Mixer tarball’s configure script recognizes that smpeg is installed
and reports no errors.

When I try to play an mp3 ("./playmus something.mp3") I get

Opened audio at 22050 Hz 16 bit stereo, 4096 bytes audio buffer
Couldn’t load something.mp3: Module format not recognized

I’ve tried with many mp3s, thinking perhaps I had one in an odd format (I know
basically nothing about audio formats), always the same error.

mpg123 will load and play the mp3 just fine. If I set the environment
MUSIC_CMD to “mpg123” which playmus in turn uses to set an external audio
player, then try it I get

Opened audio at 22050 Hz 16 bit stereo, 4096 bytes audio buffer
Playing something.mp3
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layer 1, 2 and 3.
Version 0.59r (1999/Jun/15). Written and copyrights by Michael Hipp.
Uses code from various people. See ‘README’ for more!
THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK!
audio: Resource temporarily unavailable

Which seems peculiar to me.

And finally, playmus will play midi and ogg vorbis files just fine. I’ve
looked through the sourcecode as well as some SDL_Mixer tutorials without
much luck. I don’t think it’s a coding problem.

Thanks,
Matt