I am currently going through SDL tutorials by lazyfoo on lazyfoo.net and I was wondering if someone could explain something for me. The tutorials often use code like:
to initialize functions in order to return a 1 if something goes wrong. I was wondering how you find out which function returns a 1 if the program doesn't compile correctly. I am currently using visual studio 2010.
you could also return other numbers, such as -1 or 2 or really anything I THINK (i may not be correct) so that each function returns a different error code
bool myBoolFunct()
{
//some code
//this function can return either 1 or 0;
return 1;
}
int myIntFunc()
{
//this function can return int integers
return -44;
}
char myCharFunc()
{
//this returns char
return'i';
}
unsignedint myUnsignedIntFunc()
{
//this function returns 'unsigned int'
return 108;
}
oh silly me, i knew that too :P well my sincere apologies for misleading you. Thanks eric!
note int main acts as an int function (like it's so special :P), so any for loops or if statements can return any error code in the scope of int, or return 0, which is common for showing success.
note 2, bool can also return true or false, such as if something exists or is equal to something else.
Actually you are not restricted to just the primitive type. You can have pointer to primitive type too but this can lead to memory leak if not taken care properly so usually you don't see such declaration much.
1 2 3 4 5 6 7
bool* myBoolFunct()
int* myIntFunc()
char* myCharFunc() // this one quite commonly seen so be careful !!!
unsignedint* myUnsignedIntFunc()