0

Understanding abstract declarators and their use took a lot of time and effort for me.But to my surprise,I just read abstract declarators are not necessary in function declarations.Here's what Wikipedia (LINK) says :

"It's important to be aware that a declaration of a function does not need to include a prototype. The following is a prototype-less function declaration, which just declares the function name and its return type, but doesn't tell what parameter types the definition expects.

int fac();

"

So does it mean I don't need to use abstract declarator in this declaration as :

int fac(int);

?

Please settle this thing for me conclusively.Should I assume that we dont' need to include abstract declarators during function declaration, but it is only advisable to do so?

Rüppell's Vulture
  • 3,583
  • 7
  • 35
  • 49

2 Answers2

2

Yes, you can get by with just declaring functions, not prototyping them.

That said, this is allowed only for backward compatibility. Prototypes have been in the language for decades now, and everybody in their right mind (who uses C at all) has been using prototypes for essentially that entire time. Unless you really need to write code that's compatible with a truly ancient compiler, there's absolutely no benefit (or even excuse) for writing new code that uses function declarations rather than prototypes.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
  • Sometimes it's useful still. For instance, suppose you have a library which defines `foo`, but its signature varies by library version (which is exported as an external variable). Then you could do: `int foo(); extern int foo_version; if (foo_version>=2) foo(x,0); else foo(x);` – R.. GitHub STOP HELPING ICE Apr 02 '13 at 03:55
0

prototypes provide visibility to other compilation units.

also they allow you to not have to structure your code so that definitions happen before invocations.

before anyone pipes up and says xyzcc handles this with 2 pass symbolication or whatever... don't care, C can be portable if written correctly; and should be.

Grady Player
  • 14,399
  • 2
  • 48
  • 76