Consider these styles for a single source file program.
Form 1
Form 2
Form 3
I personally prefer form 3 above. Form 1 violates the DRY or don't repeat yourself principle. I see quite a bit of code using form 1 which doesn't actually need prototypes and also exports the symbols to the linker instead of marking them as static and file scope. If you add or remove parameters to functions A or B - or change the return type - you need to remember to touch both locations. Why incur the risk?
Unless I have a pair of codependent functions, I can usually avoid the prototype.
As before, no reply needed. I just like to complain.
Form 1
Code:
void A(int x, int y);
int B(float x);
int main(int argc, const char *argv[])
{
A(1, 2);
return B(3.f);
}
void A(int x, int y)
{
// some code goes here.
}
int B(float x)
{
// do something with x
return 0;
}
Form 2
Code:
void A(int x, int y)
{
// some code goes here.
}
int B(float x)
{
// do something with x
return 0;
}
int main(int argc, const char *argv[])
{
A(1, 2);
return B(3.f);
}
Form 3
Code:
static void A(int x, int y)
{
// some code goes here.
}
static int B(float x)
{
// do something with x
return 0;[/ICODE]
}
int main(int argc, const char *argv[])
{
A(1, 2);
return B(3.f);
}
Unless I have a pair of codependent functions, I can usually avoid the prototype.
As before, no reply needed. I just like to complain.