Hey all, this is my first time posting but I've lurked here for quite awhile!
Right now I am attempting to make a text based game and I am looking at the source code from a similar, open-sourced project(NetHack). I recently found some code that confused me:
1 2 3 4 5 6 7 8 9
int
def_char_to_objclass(ch)
char ch;
{
int i;
for (i = 1; i < MAXOCLASSES; i++)
if (ch == def_oc_syms[i]) break;
return i;
}
What exactly is that char ch; on line 3 supposed to be doing and why is it outside of the method body? Is this a way of coding methods from the old days of C? Thanks for any help.
Yes, it is the (quite) old style for declaring functions. That char ch; line is telling the compiler that ch is a char. Don't use it. I think it's been deprecated as of C99.
Don't use in your new C/C++ program but you must know the syntax cuz you never know you are tasked by your employers to do maintenance for legacy C program. Some organizations use program for many many years and still did not de-commission them :P