This maybe a completely obvious error but I can't figure out why my code below won't work. I'm rather unfamiliar with C, though I have made some programs using it.
I'm using Turbo C (v.3.2), so that might also be the issue; however, I'm not sure.
static struct sector
{
float floor, ceil;
vec2 *verts;
signed char *neighbors;
unsigned npoints;
}*sectors = NULL;
static unsigned NumSectors = 0;
static struct player
{
vec3 position, velocity;
float anlge, anglesin, anglecos, yaw;
unsigned sector;
}player;
void DrawScreen()
{
enum{ MaxQueue = 32 };
unsigned s = 0;
struct item { int sectorno,sx1, sx2; } queue[MaxQueue], *head=queue, *tail=queue;
int ytop[W]={0}, ybottom[W], *renderedsectors = (int*)malloc(NumSectors*sizeof(int));
for(s = 0; s < W; ++s) ybottom[s] = H-1;
for(s = 0; s < NumSectors; ++s) renderedsectors[s] = 0;
//This line causes an Expression syntax error.
//From my understanding the pointer is moved to this structure inside the array.
//Corrections welcome as I want to learn c more in order to
//use it in more projects of mine.
*head = (struct item) { player.sector, 0, W-1 };
if(++head == queue+MaxQueue) head = queue;
do{
const struct item now = *tail;
const struct sector* const sect = §ors[now.sectorno];
if(++tail == queue+MaxQueue) tail = queue;
if(renderedsectors[now.sectorno] & 0x21) continue;
++renderedsectors[now.sectorno];
for(s = 0; s < sect->npoints; ++s)
{
}
}while(head != tail);
}
I'm aware of the age of Turbo C but I have to use it due to it running in DOSBox, where my final executable has to work.
I'm copying the code from this website and I'm pretty sure he used another compiler, which probably was also newer.
I didn't work a lot with C and I mostly either used C++ in my free time or C# on the job, but I need to use it now due to the restrictions I'm facing.
The line of code that is causing your error message (shown below) is using what is known as a compound literal. This allows an anonyomus object of the type specified in the parentheses to be constructed from the data provided in the initializer list (inside the braces).
The problem you're facing is that this construct was only incorporated into the C language in the "C99" (formally, ISO/IEC 9899:1999) version of the Standard – which, as it's name implies, was published in 1999.
However, the compiler you are using (Turbo C, v3.2) was released in or around 1993, so it almost certainly does not support this feature. (Some pre-1999 compilers may have supported compound literals as extensions but I doubt that Turbo C was one of them.)
There are two things you can do to circumvent the error:
*headtarget:Note that, in the second case, your
tempvariable will have the same scope (and lifetime) as the anonymous object created by the compound literal.