C 大量语法错误
我正在尝试用C和SDL创建一个小游戏,以一种有趣的方式开始使用SDL。我将粘贴我的计时器结构和函数,用于在我的主游戏循环中限制fps。但我得到了很多“错误C2054:预期'('跟随't'”),总共大约25个错误 这是:C 大量语法错误,c,C,我正在尝试用C和SDL创建一个小游戏,以一种有趣的方式开始使用SDL。我将粘贴我的计时器结构和函数,用于在我的主游戏循环中限制fps。但我得到了很多“错误C2054:预期'('跟随't'”),总共大约25个错误 这是: #include <stdio.h> #include <stdlib.h> #include <string.h> #include "SDL.h" struct Timer { int startTicks; int
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SDL.h"
struct Timer {
int startTicks;
int pausedTicks;
int paused;
int started;
};
void Init( Timer *t )
{
t->startTicks = 0;
t->pausedTicks = 0;
t->paused = 0;
t->started = 0;
}
void StartTimer( Timer *t )
{
t->started = 1;
t->paused = 0;
t->startTicks = SDL_GetTicks();
}
void StopTimer( Timer *t )
{
t->started = 0;
t->paused = 0;
}
void PauseTimer( Timer *t )
{
if( t->started == 1 && t->paused == 0 )
{
t->paused = 1;
t->pausedTicks = SDL_GetTicks() - t->startTicks;
}
}
void UnpauseTimer( Timer *t )
{
if( t->paused == 1 )
{
t->paused = 0;
t->startTicks = SDL_GetTicks() - t->pausedTicks;
t->pausedTicks = 0;
}
}
int GetTicks( Timer *t )
{
if( t->started == 1 )
{
return t->pausedTicks;
}
else
{
return SDL_GetTicks() - t->startTicks;
}
return 0;
}
#包括
#包括
#包括
#包括“SDL.h”
结构计时器{
int startTicks;
int暂停时间;
int暂停;
int开始;
};
void Init(计时器*t)
{
t->startTicks=0;
t->pausedTicks=0;
t->暂停=0;
t->start=0;
}
无效起始计时器(计时器*t)
{
t->start=1;
t->暂停=0;
t->startTicks=SDL_GetTicks();
}
无效停止计时器(计时器*t)
{
t->start=0;
t->暂停=0;
}
无效暂停定时器(定时器*t)
{
如果(t->start==1&&t->paused==0)
{
t->暂停=1;
t->pausedTicks=SDL_GetTicks()-t->startTicks;
}
}
无效取消暂停(计时器*t)
{
如果(t->暂停==1)
{
t->暂停=0;
t->startTicks=SDL_GetTicks()-t->pausedTicks;
t->pausedTicks=0;
}
}
int GetTicks(计时器*t)
{
如果(t->started==1)
{
返回t->pausedTicks;
}
其他的
{
返回SDL_GetTicks()-t->startTicks;
}
返回0;
}
这里出了什么问题?提前谢谢!所有这些
t
变量都应该是struct Timer
类型,而不是Timer
或者,将其定义为:
typedef struct sTimer {
int startTicks;
int pausedTicks;
int paused;
int started;
} Timer;
要使计时器成为“一流”类型。在C中,您需要执行以下操作:
struct Foo
{
...
};
...
void bar(struct Foo *p);
^
或者这个:
typedef struct Foo
{ ^
...
} Foo;
^
...
void bar(Foo *p);
[我更喜欢第二个版本;它省去了到处写
struct
。]找到第一个错误并从中解决。通常,其他许多错误都是第一个错误的后果。找到了所有包含的文件吗?请仔细阅读错误消息-哪一行是“错误C2054”我会开始在那里搜索错误:)通常是/