Help decifering problem with code

Here are my compile errors:
gcc -o run main.c game.c sdl-config --cflags --libs
main.c:24: syntax error before "event"
main.c:24: warning: data definition has no type or storage class

I am using Linux Enterprise WS 3.0 with kernel 2.4. I am using
SDL-1.2.7. I can not get this program to compile completely. Here is
the code:

// main.c – Game Startup

#include<SDL.h>
#include<stdlib.h>
#include <stdio.h>
#include “game.h”

typedef union {
Uint8 type;
Uint8 state;
SDL_ActiveEvent active;
SDL_KeyboardEvent key;
SDL_MouseMotionEvent motion;
SDL_MouseButtonEvent button;
SDL_JoyAxisEvent jaxis;
SDL_JoyBallEvent jball;
SDL_JoyHatEvent jhat;
SDL_JoyButtonEvent jbutton;
SDL_ResizeEvent resize;
SDL_QuitEvent quit;
SDL_UserEvent user;
SDL_SysWMEvent syswm;
SDL_keysym keysym;
} SDL_KeyboardEvent event; /* This is where my problem is
occuring…line 22 */
char *title_string = “Lemonade Game for CPSC 481/681 version 1.0”;
static SDL_Surface *screen;
int SDL_PollEvent(SDL_Event *event);
int SDL_WaitEvent(SDL_Event *event);
char IsMessage(void) {
char message_waiting = 0;
// Code to check for messages goes here

 if(message_waiting) {
       return 1;
 } else {
      return 0;
 }

}

void *GetMessage(void) {
void *message;
// Code to retrieve message from queue goes here

 return message;

}

void ProcessMessage(void *message) {
// Process the message here

}

int main(int argc, char **argv) {
void *message;
SDL_Surface *background;
SDL_Rect src, dest;
SDL_Event event;

 // Display game title message
 fprintf(stderr, title_string);


 // Startup code goes here
 // Initialize SDL
 if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) != 0) {
 fprintf(stderr, "SDL Error: %s\n", SDL_GetError());
 return 0;
 }
 atexit(SDL_Quit);
 screen = SDL_SetVideoMode(
     640, 480,           // width and height of window
     16,                 // 16 bit color depth
     SDL_HWSURFACE | SDL_DOUBLEBUF    // video flags
 );

 if(screen == NULL) {
    fprintf(stderr, "Video error: %s\n", SDL_GetError());
    exit(1);
 }

 SDL_WM_SetCaption(title_string, NULL);

 /* Load the bitmap files. */
background = SDL_LoadBMP("background.bmp");
if (background == NULL)
{
    printf("Unable to load bitmap.\n");
    return 1;
}

/* Draw the background image. */
src.x = 0;
src.y = 0;
src.w = background->w;
src.h = background->h;
dest = src;

/* Flip the page. */
SDL_Flip(screen);


/* Hide the mouse pointer. */
SDL_ShowCursor(0);


// Draw image
SDL_BlitSurface(background, &src, screen, &dest);

// Ask SDL to update the entire screen.
SDL_UpdateRect(screen, 0, 0, 0, 0);

/* Update SDL’s internal input state information. */
int quit = 0;

/* Grab a snapshot of the keyboard. /
while(!quit){
/
Wait for an event /
if(SDL_WaitEvent(&event)) {
/
When an event is received, check if it’s a /
/
SDL_KEYDOWN event, if so then set the quit flag */
if(event.type==SDL_KEYDOWN) quit=1;
}
}
void HandleEvents() {
SDL_Event event;

/* Loop until all events have been removed from the queue */
while(SDL_PollEvent(&event)) {

/* Jump to an approapriate handler /
/
Depending on the event type */
switch(event.type) {

/* Keyboard Events */
case SDL_KEYDOWN:
case SDL_KEYUP:
HandleKeyboardEvent(&event);
break;

/* Mouse Events */
case SDL_MOUSEMOTION:
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
HandleMouseEvent(&event);
break;

/* Joystick Events */
case SDL_JOYAXISMOTION:
case SDL_JOYHATMOTION:
case SDL_JOYBALLMOTION:
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
HandleJoysstickEvent(&event);
break;

/* Miscellaneous Events */
default:
HandleMiscEvent(&event);
break;
}
}
}

// Enter main game loop
while (1) {
      // Check the message queue
      if(IsMessage()) {

      // There is a message, so process it
      message = GetMessage();
      ProcessMessage(message);
   } else {
     // No message, so perform standard stuff
     gameloop();
   }
}

// Shutdown code goes here
/* Free the memory that was allocated to the bitmap. */
SDL_FreeSurface(background);

/* Exitly cleanly */
SDL_Quit();
return 1;

}

I appreciate any input!

– Dexter

The reason the compiler is giving you that error is that you are
declaring a type called SDL_KeyboardEvent which is an anonymous union,
and in the same statement you pretend to also declare a variable of
that type.

It is like the following: typedef unsigned int Uint my_varuint;

of course the compiler is going to complain about my_varuint;

try declaring event in another line of code, another statement:
SDL_KeyboardEvent event;

by the way, I wouldn’t use the anonymous union, use C++ style naming
better, and don’t include the prototypes of functions you are already
importing through SDL.hOn Thu, 4 Nov 2004 23:22:10 -0500, Dexter Stowers <dexter.stowers at gmail.com> wrote:

Here are my compile errors:
gcc -o run main.c game.c sdl-config --cflags --libs
main.c:24: syntax error before "event"
main.c:24: warning: data definition has no type or storage class

I am using Linux Enterprise WS 3.0 with kernel 2.4. I am using
SDL-1.2.7. I can not get this program to compile completely. Here is
the code:

// main.c – Game Startup

#include<SDL.h>
#include<stdlib.h>
#include <stdio.h>
#include “game.h”

typedef union {
Uint8 type;
Uint8 state;
SDL_ActiveEvent active;
SDL_KeyboardEvent key;
SDL_MouseMotionEvent motion;
SDL_MouseButtonEvent button;
SDL_JoyAxisEvent jaxis;
SDL_JoyBallEvent jball;
SDL_JoyHatEvent jhat;
SDL_JoyButtonEvent jbutton;
SDL_ResizeEvent resize;
SDL_QuitEvent quit;
SDL_UserEvent user;
SDL_SysWMEvent syswm;
SDL_keysym keysym;
} SDL_KeyboardEvent event; /* This is where my problem is
occuring…line 22 */
char *title_string = “Lemonade Game for CPSC 481/681 version 1.0”;
static SDL_Surface *screen;
int SDL_PollEvent(SDL_Event *event);
int SDL_WaitEvent(SDL_Event *event);
char IsMessage(void) {
char message_waiting = 0;
// Code to check for messages goes here

 if(message_waiting) {
       return 1;
 } else {
      return 0;
 }

}

void *GetMessage(void) {
void *message;
// Code to retrieve message from queue goes here

 return message;

}

void ProcessMessage(void *message) {
// Process the message here

}

int main(int argc, char **argv) {
void *message;
SDL_Surface *background;
SDL_Rect src, dest;
SDL_Event event;

 // Display game title message
 fprintf(stderr, title_string);

 // Startup code goes here
 // Initialize SDL
 if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) != 0) {
 fprintf(stderr, "SDL Error: %s\n", SDL_GetError());
 return 0;
 }
 atexit(SDL_Quit);
 screen = SDL_SetVideoMode(
     640, 480,           // width and height of window
     16,                 // 16 bit color depth
     SDL_HWSURFACE | SDL_DOUBLEBUF    // video flags
 );

 if(screen == NULL) {
    fprintf(stderr, "Video error: %s\n", SDL_GetError());
    exit(1);
 }

 SDL_WM_SetCaption(title_string, NULL);

 /* Load the bitmap files. */
background = SDL_LoadBMP("background.bmp");
if (background == NULL)
{
    printf("Unable to load bitmap.\n");
    return 1;
}

/* Draw the background image. */
src.x = 0;
src.y = 0;
src.w = background->w;
src.h = background->h;
dest = src;

/* Flip the page. */
SDL_Flip(screen);

/* Hide the mouse pointer. */
SDL_ShowCursor(0);

// Draw image
SDL_BlitSurface(background, &src, screen, &dest);

// Ask SDL to update the entire screen.
SDL_UpdateRect(screen, 0, 0, 0, 0);

/* Update SDL’s internal input state information. */
int quit = 0;

/* Grab a snapshot of the keyboard. /
while(!quit){
/
Wait for an event /
if(SDL_WaitEvent(&event)) {
/
When an event is received, check if it’s a /
/
SDL_KEYDOWN event, if so then set the quit flag */
if(event.type==SDL_KEYDOWN) quit=1;
}
}
void HandleEvents() {
SDL_Event event;

/* Loop until all events have been removed from the queue */
while(SDL_PollEvent(&event)) {

/* Jump to an approapriate handler /
/
Depending on the event type */
switch(event.type) {

/* Keyboard Events */
case SDL_KEYDOWN:
case SDL_KEYUP:
HandleKeyboardEvent(&event);
break;

/* Mouse Events */
case SDL_MOUSEMOTION:
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
HandleMouseEvent(&event);
break;

/* Joystick Events */
case SDL_JOYAXISMOTION:
case SDL_JOYHATMOTION:
case SDL_JOYBALLMOTION:
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
HandleJoysstickEvent(&event);
break;

/* Miscellaneous Events */
default:
HandleMiscEvent(&event);
break;
}
}
}

// Enter main game loop
while (1) {
      // Check the message queue
      if(IsMessage()) {

      // There is a message, so process it
      message = GetMessage();
      ProcessMessage(message);
   } else {
     // No message, so perform standard stuff
     gameloop();
   }
}

// Shutdown code goes here
/* Free the memory that was allocated to the bitmap. */
SDL_FreeSurface(background);

/* Exitly cleanly */
SDL_Quit();
return 1;

}

I appreciate any input!

– Dexter


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


“The reasonable man adapts himself to the world: the unreasonable one
persists in trying to adapt the world to himself. Therefore all
progress depends on the unreasonable man.” George Bernard Shaw

“We live together, you and I, in a dark time when all official history
is propaganda” John Taylor Gatto,
http://www.johntaylorgatto.com/underground/prologue7.htm

Here are my compile errors:
gcc -o run main.c game.c sdl-config --cflags --libs
main.c:24: syntax error before "event"
main.c:24: warning: data definition has no type or storage class

I am using Linux Enterprise WS 3.0 with kernel 2.4. I am using
SDL-1.2.7. I can not get this program to compile completely. Here is
the code:

// main.c – Game Startup

#include<SDL.h>
#include<stdlib.h>
#include <stdio.h>
#include “game.h”

typedef union {
Uint8 type;
Uint8 state;
SDL_ActiveEvent active;
SDL_KeyboardEvent key;
SDL_MouseMotionEvent motion;
SDL_MouseButtonEvent button;
SDL_JoyAxisEvent jaxis;
SDL_JoyBallEvent jball;
SDL_JoyHatEvent jhat;
SDL_JoyButtonEvent jbutton;
SDL_ResizeEvent resize;
SDL_QuitEvent quit;
SDL_UserEvent user;
SDL_SysWMEvent syswm;
SDL_keysym keysym;
} SDL_KeyboardEvent event; /* This is where my problem is
occuring…line 22 */

Doesn’t look like valid C to me. Normally you would not have two
identifiers in a row after a typedef. Then there is a the problem that
you are trying to redefine SDL_KeyboardEvent, which is already defined
and used in the union. Not to mention that you are apparently trying to
redefine the SDL event structure which you can’t do in your program, you
have to modify the SDL include files and recompile all of SDL to do
that. Any anyway, since it is a union adding that “state” field the way
you have just makes “state” another name for “type” so when you assign
something to it you will clobber the value of “type”.

char *title_string = “Lemonade Game for CPSC 481/681 version 1.0”;

Oh, you are asking for help with your home work. Some schools consider
asking mailing lists for help with homework to be cheating. You should
check your school rules before you do it again. Wouldn’t want to get
kicked out of school for cheating. :slight_smile:

static SDL_Surface *screen;
int SDL_PollEvent(SDL_Event *event);
int SDL_WaitEvent(SDL_Event *event);

You don’t need to declare these functions, they are declared in SDL.h.

		Bob PendletonOn Thu, 2004-11-04 at 22:22, Dexter Stowers wrote:

char IsMessage(void) {
char message_waiting = 0;
// Code to check for messages goes here

 if(message_waiting) {
       return 1;
 } else {
      return 0;
 }

}

void *GetMessage(void) {
void *message;
// Code to retrieve message from queue goes here

 return message;

}

void ProcessMessage(void *message) {
// Process the message here

}

int main(int argc, char **argv) {
void *message;
SDL_Surface *background;
SDL_Rect src, dest;
SDL_Event event;

 // Display game title message
 fprintf(stderr, title_string);


 // Startup code goes here
 // Initialize SDL
 if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) != 0) {
 fprintf(stderr, "SDL Error: %s\n", SDL_GetError());
 return 0;
 }
 atexit(SDL_Quit);
 screen = SDL_SetVideoMode(
     640, 480,           // width and height of window
     16,                 // 16 bit color depth
     SDL_HWSURFACE | SDL_DOUBLEBUF    // video flags
 );

 if(screen == NULL) {
    fprintf(stderr, "Video error: %s\n", SDL_GetError());
    exit(1);
 }

 SDL_WM_SetCaption(title_string, NULL);

 /* Load the bitmap files. */
background = SDL_LoadBMP("background.bmp");
if (background == NULL)
{
    printf("Unable to load bitmap.\n");
    return 1;
}

/* Draw the background image. */
src.x = 0;
src.y = 0;
src.w = background->w;
src.h = background->h;
dest = src;

/* Flip the page. */
SDL_Flip(screen);


/* Hide the mouse pointer. */
SDL_ShowCursor(0);


// Draw image
SDL_BlitSurface(background, &src, screen, &dest);

// Ask SDL to update the entire screen.
SDL_UpdateRect(screen, 0, 0, 0, 0);

/* Update SDL’s internal input state information. */
int quit = 0;

/* Grab a snapshot of the keyboard. /
while(!quit){
/
Wait for an event /
if(SDL_WaitEvent(&event)) {
/
When an event is received, check if it’s a /
/
SDL_KEYDOWN event, if so then set the quit flag */
if(event.type==SDL_KEYDOWN) quit=1;
}
}
void HandleEvents() {
SDL_Event event;

/* Loop until all events have been removed from the queue */
while(SDL_PollEvent(&event)) {

/* Jump to an approapriate handler /
/
Depending on the event type */
switch(event.type) {

/* Keyboard Events */
case SDL_KEYDOWN:
case SDL_KEYUP:
HandleKeyboardEvent(&event);
break;

/* Mouse Events */
case SDL_MOUSEMOTION:
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
HandleMouseEvent(&event);
break;

/* Joystick Events */
case SDL_JOYAXISMOTION:
case SDL_JOYHATMOTION:
case SDL_JOYBALLMOTION:
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
HandleJoysstickEvent(&event);
break;

/* Miscellaneous Events */
default:
HandleMiscEvent(&event);
break;
}
}
}

// Enter main game loop
while (1) {
      // Check the message queue
      if(IsMessage()) {

      // There is a message, so process it
      message = GetMessage();
      ProcessMessage(message);
   } else {
     // No message, so perform standard stuff
     gameloop();
   }
}

// Shutdown code goes here
/* Free the memory that was allocated to the bitmap. */
SDL_FreeSurface(background);

/* Exitly cleanly */
SDL_Quit();
return 1;

}

I appreciate any input!

– Dexter


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

±-------------------------------------+