Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This noncompliant code example omits the type specifier.

Code Block
bgColor#FFCCCC
langc
extern foo;

Most C90 implementations do not issue a diagnostic for the violation of this C99 constraint. Many C99 translators will continue to treat such declarations as implying the type int.

...

This compliant solution explicitly includes a type specifier.

Code Block
bgColor#ccccff
langc
extern int foo;

Noncompliant Code Example (Implicit Function Declaration)

...

However, to conform with C99, you must explicitly prototype every function before invoking it. This noncompliant example fails to prototype the foo() function before invoking it in main().

Code Block
bgColor#FFCCCC
langc
int main(void) {
  int c = foo();
  printf("%d\n", c);
  return 0;
}

int foo(int a) {
  return a;
}

...

In this compliant solution, a prototype for foo() appears before the function invocation.

Code Block
bgColor#ccccff
langc
int foo(int);

int main(void) {
  int c = foo(0);
  printf("%d\n", c);
  return 0;
}

int foo(int a) {
  return a;
}

...

Similarly, do not declare a function with implicit return type. If it returns a meaningful integer value, declare it int. If it returns no meaningful value, declare it void.

Code Block
bgColor#ffcccc
langc
foo(void) {
  return UINT_MAX;
}

int main(void) {
  long long c = foo();
  printf("%lld\n", c);
  return 0;
}

...

This compliant solution explicily defines the return type of foo() as unsigned int.

Code Block
bgColor#ccccff
langc
unsigned int foo(void) {
  return UINT_MAX;
}

int main(void) {
  long long c = foo();
  printf("%lld\n", c);
  return 0;
}

...