Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notation I can't understand in Quake source code (C)

Tags:

c

header

quake

I was taking a look at the Quake 1 GPL Code and I came across various similar header files, the purpose or use of which I don't seem to understand. They look like tables of some sorts and are structured like this

{1, 0},
{1, -1},
{1, -2},
{1, -3},
{1, -4},
{1, -5},[...]

Without anything before or after them. I understand they define something but I've never come across this kind of notation in C. You can read one of the header files I'm referring to here.

My question is: what are those...things? The ASM is actually giving me less problems than that stuff.

like image 398
Viktor Avatar asked Dec 03 '10 10:12

Viktor


3 Answers

These are probably multi-use includes. They can be used like so:

struct {int y; int y;} points[] = {
#include <points.inl>
};
like image 83
frast Avatar answered Sep 28 '22 06:09

frast


The contents of a header do not have to be valid C; the C preprocessor will insert them wherever the #include directive is found, such as in the middle of a struct initialization in another source file. As long as it's valid C by the time it actually gets to the compiler, that's all that matters.

like image 43
Ignacio Vazquez-Abrams Avatar answered Sep 28 '22 06:09

Ignacio Vazquez-Abrams


They can be used to initialize arrays.

You could use them like this:

int array[N][2] =
#include <header_file>
;
like image 41
peoro Avatar answered Sep 28 '22 08:09

peoro