Seite 1 von 2

expected semikolon bei Default Parametern

Verfasst: Mi Mai 15, 2013 1:52 pm
von hardcoding
Hallo,

Ich versuche momentan den folgenden Code zum kompilieren. Ein Bild soll per Pfeiltasten bewegt werden.
Sobald ich das kompliere liefert er mir eine Fehlermeldung und zwar:

Code: Alles auswählen

\Garten-Animation.c|83|error: expected ';', ',' or ')' before '=' token|
In Zeile 83 soll ein Semikolon Fehler oder sowas ähnliches sein .Ich bin leider zu blöd um den Fehler zu finden. :roll:
Zeile 83:

Code: Alles auswählen

void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL )
{
    //Holds offsets


    //Get offsets
    offset.x = x;
    offset.y = y;

    //Blit
    SDL_BlitSurface( source, clip, destination, &offset );
}
Vielleicht kann mir hier jemand helfen und danke im Voraus.

Code: Alles auswählen

#include "SDL/SDL.h"
#include "SDL/SDL_image.h"


const int Kind_h = 20;
const int Kind_w = 20;


SDL_Surface* Hintergrund = NULL;
SDL_Surface* garten  = NULL;
SDL_Surface* kind = NULL;

SDL_Rect rc;

SDL_Event Event;


int x = 0,y = 0;
int xVel = 0, yVel = 0;




void keytaste()
{

    if(Event.type == SDL_KEYDOWN)
    {
        switch(Event.key.keysym.sym)
        {
        case SDLK_UP:
            yVel-=Kind_h/2;
            break;
        case SDLK_DOWN:
            yVel+=Kind_h/2;
            break;
        case SDLK_LEFT:
            xVel-=Kind_w/2;
            break;
        case SDLK_RIGHT:
            xVel+=Kind_w/2;
            break;

        }
    }
    else if(Event.type == SDL_KEYUP)
    {
        switch(Event.key.keysym.sym)
        {
        case SDLK_UP:
            yVel+=Kind_h/2;
            break;
        case SDLK_DOWN:
            yVel-=Kind_h/2;
            break;
        case SDLK_LEFT:
            xVel+=Kind_w/2;
            break;
        case SDLK_RIGHT:
            xVel-=Kind_w/2;
            break;
        }

    }
}

void show();


void move()
{
    x += xVel;

    if( ( x < 0 ) || ( x + Kind_w > 640 ) )
    {
        //move back
        x -= xVel;
    }

    //Move the dot up or down
    y += yVel;

    //If the dot went too far up or down
    if( ( y < 0 ) || ( y + Kind_h > 480 ) )
    {
        //move back
        y -= yVel;
    }
}





void show()
{

    apply_surface(x,y,kind,Hintergrund);
}

void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL )
{
    //Holds offsets


    //Get offsets
    offset.x = x;
    offset.y = y;

    //Blit
    SDL_BlitSurface( source, clip, destination, &offset );
}



int main(int argc,char* argv[])
{

    SDL_Init(SDL_INIT_EVERYTHING);
    SDL_Quit();

    Hintergrund = SDL_SetVideoMode(640,480,0,SDL_ANYFORMAT);
    garten = IMG_Load("Garten.jpg");
    kind   = IMG_Load("Kind.jpg");

    rc.w=kind->w;
    rc.h=kind->h;


    for(;;)
    {
        if(SDL_PollEvent(&Event)==0)
        {

            keytaste();
            move();
            show();
            SDL_BlitSurface(garten,0,Hintergrund,0);
            SDL_UpdateRect(Hintergrund,0,0,0,0);
        }

    }

    return(0);
}
Edit By Xin: Betreff detailierter

Re: expected semikolon

Verfasst: Mi Mai 15, 2013 1:57 pm
von cloidnerux
Kann es sein, dass das vorbelegen von deinem Compiler nicht unterstütz wird?

Re: expected semikolon

Verfasst: Mi Mai 15, 2013 2:00 pm
von hardcoding
Kann es sein, dass das vorbelegen von deinem Compiler nicht unterstütz wird?
Wie meinst du das ? Ich verstehe das nicht ganz.

Re: expected semikolon

Verfasst: Mi Mai 15, 2013 2:03 pm
von darksider3
Ich glaube, es wäre schön zu Wissen welchen Compiler Du nutzt, um herauszufinden ob dieser die Vorbelegung unterstützt.

Re: expected semikolon

Verfasst: Mi Mai 15, 2013 2:05 pm
von hardcoding
Ich glaube, es wäre schön zu Wissen welchen Compiler Du nutzt, um herauszufinden ob dieser die Vorbelegung unterstützt.
Achso GNU GCC Compiler.

Re: expected semikolon

Verfasst: Mi Mai 15, 2013 2:06 pm
von darksider3
Version?
Mach um das Herauszufinden einfach mal ein beherztes

Code: Alles auswählen

gcc -v
:mrgreen:

Re: expected semikolon

Verfasst: Mi Mai 15, 2013 2:14 pm
von hardcoding
Keine Ahnung.

In Windows Readme Datei steht GCC 4.6 & 4.7 Series mingw 32

Re: expected semikolon

Verfasst: Mi Mai 15, 2013 2:19 pm
von cloidnerux
Nimm mal bei dem

Code: Alles auswählen

SDL_Rect* clip = NULL
das "= NULL" heraus und schaue, ob das Abhilfe schafft.

Re: expected semikolon

Verfasst: Mi Mai 15, 2013 2:22 pm
von Xin
Das ist eine .c Datei. Für Default-Parameter musst Du C++ kompilieren. (g++ verwenden)

Re: expected semikolon

Verfasst: Mi Mai 15, 2013 2:27 pm
von hardcoding
Das ist eine .c Datei. Für Default-Parameter musst Du C++ kompilieren. (g++ verwenden)
ahh vollkommen übersehen. Das Klappt aber das stürzt nun immer ab. Naja muss sehen wie ich das hinbekomme.