Anything starting with '#' is a preprocessor directive.
#include "blah.h" will basically perform a copy/paste of blah.h where that line is (Hence 'include guards' are needed)
#define is used for macros. A way to get the preprocessor to write code for you.
I use this for my long list of 'script command' handler function declarations
[php]#define SC_DECL( x ) void x( const char *args )
SC_DECL( OpenMenu );
SC_DECL( CloseMenu );
SC_DECL( PlaySound );
SC_DECL( ExitGame );
#undef SC_DECL[/php]
Output is
[php]void OpenMenu( const char *args );
void CloseMenu( const char *args );
void PlaySound( const char *args );
void ExitGame( const char *args );[/php]
Then there are the 'base types' for declaring variables, functions, etc.
bool = C++ keyword. The value can only be 'true' or 'false'. Size is 1
bit. (Unless it's stored as a byte - I'm unsure, but probably is)
int = C/C++ keyword. An integer, WORD size of the machine (assumed 32 bits). Numbers like -10, -4, 0, 1, 2, 3, 223
long = C/C++ keyword. At-least 32 bits(?), same values as int
float = C/C++ keyword. Floating point number with single-precision. Numbers like 0.3f, 0.345345f, 3.14159265f.
double = C/C++ keyword. Floating point number with double-precision. Same values as above, but more precise.
char = C/C++ keyword. A single character, treated as a number between -127<->127 or 0<->255 depending on signed/unsigned. A "string" is a sequence of characters terminated by 0 (So the program knows where a string ends, otherwise it'd read on forever through memory)
void = C/C++ keyword. Used for pointers with no logical type, and functions that don't have a return value. It can't hold a value (Aside from a pointer)
It's important to learn the sizes of each variable type. Google/Wiki this
signed/unsigned - Tells whether the number
can be negative or not.
For a signed variable, the MSB (Most-significant-bit, machine dependent) controls whether the number is treated as negative or not. Wiki this.
return - Used in a function to stop execution of that function. Useful for error handling.
for - A keyword used for looping.
syntax:
[php]for ( initialisation; condition; statement )
{
body
}[/php]
Order of execution:
- initialisation
- condition
- if condition was met, body. otherwise, end loop
- statement
- condition
- if condition was met, body. otherwise, end loop
[php]int i;
for ( i=0; i<10; i++ )
{
//Do this until i == 10, incrementing i each loop
}[/php]
-- too lazy to continue