30 Sep, 2009, JohnnyStarr wrote in the 1st comment:
Votes: 0
I've noticed in ROM that prototypes are declared with a macro called 'args'
example:
void foo        args (( CHAR_DATA *ch, char *argument ));
// instead of
void foo ( CHAR_DATA *ch, char *argument );


I know what this is doing, what I don't get is why this is desired, when the first example works fine?
Kind of a short question for a thread, but I couldn't figure out where else to put it.

Bonus Question! :)
If you declare a prototype for a local function, is it good practice to have both a header prototype, and local?
Example:

// at top of foo.c
void foo ( CHAR_DATA *ch );

// in mud.h
void foo ( CHAR_DATA *ch );
30 Sep, 2009, Koron wrote in the 2nd comment:
Votes: 0
Apparently it's desirable so you can…
Quote
/*
* Accommodate old non-Ansi compilers.
*/


As far as the bonus question goes, I don't know what the point of that would be. You put it in the .h file so it can be accessed outside of the .c file it's in, so why have both? Wouldn't having both generate a warning message anyway?
30 Sep, 2009, David Haley wrote in the 3rd comment:
Votes: 0
Koron said:
Wouldn't having both generate a warning message anyway?

Not if the declarations match.

staryavsky said:
If you declare a prototype for a local function, is it good practice to have both a header prototype, and local?

If it's meant to be a function local to the .c file it's in, you wouldn't be it into the .h file – because you don't mean to export it. If it's meant to be exported to other object files, then you would put it into the .h file. You would typically not put it into the .c file (you'd put the definition there), assuming that the .c file includes the .h file with the declaration.
30 Sep, 2009, MacGregor wrote in the 4th comment:
Votes: 0
David Haley said:
Koron said:
Wouldn't having both generate a warning message anyway?

Not if the declarations match.


Unless you have -Wredundant-decls turned on.
30 Sep, 2009, David Haley wrote in the 5th comment:
Votes: 0
Yes, that is correct. However, that warning is not turned on with -Wall or even –pedantic.

$ cat test.c

#include <stdio.h>

#include "test.h"

int foo(int i)
{
return i;
}

int main()
{
printf("%i\n", foo(2));

return 0;
}

$ cat test.h

int foo(int i);

$ gcc -Wall –pedantic test.c
$


(With gcc 4.3.3 at least.)
30 Sep, 2009, Guest wrote in the 6th comment:
Votes: 0
Koron said:
Apparently it's desirable so you can…
Quote
/*
* Accommodate old non-Ansi compilers.
*/


What platforms even exist today that aren't ANSI compilers anyway?
30 Sep, 2009, David Haley wrote in the 7th comment:
Votes: 0
I cleverly forgot to post the updated test.c with the redundant declaration.

#include <stdio.h>

#include "test.h"

int foo(int i);

int foo(int i)
{
return i;
}

int main()
{
printf("%i\n", foo(2));

return 0;
}


And yes, I agree with Samson: supporting compilers that are so old that they're not even ANSI seems somewhat unhelpful…
01 Oct, 2009, JohnnyStarr wrote in the 8th comment:
Votes: 0
hehe, that's exactly what I was thinking. Also, I don't know if anyone is going to want to
use my code base when I'm done, so I figure I'll design it for me, and if anyone actually wanted to port
it to a non ANSI compiler then 'have at it' :smirk:
01 Oct, 2009, David Haley wrote in the 9th comment:
Votes: 0
It's probably relatively hard to even find a system without an ANSI compiler. The Lua team, for example, rather known for not liking newer compiler features because they aren't supported on many embedded platforms, considers ANSI C compilers to be essentially universal for all intents and purposes – and Lua is used on some fairly esoteric platforms (in particular, various embedded systems).
0.0/9