-1

I have a query with below code. How does the below code gets interpreted as per K&R c? There is no compilation error and the code runs just fine. I have used -traditional in build option in codeblocks. Searched around for a while but could not get a satisfactory answer.

void func(int);

int main(void) {
    func(10);
    return 0;
}

void func(void){
}
too honest for this site
  • 12,050
  • 4
  • 30
  • 52
Soujanya
  • 59
  • 4
  • 6
    `-traditional` only affect the preprocessor. the code you show should not compile. – fuz Apr 16 '16 at 16:19
  • 3
    In addition to other posts here: Don't write K&R-C code anymore. At least use C99, better standard C. Also note: K&R-C is **not** ANSI-C aka C89 (or C90, there are no differences in the language). – too honest for this site Apr 16 '16 at 16:48
  • Why should you even think about something like this? function definition and declaration should have the same parameters. like @olaf said, forget that K&R even existed. Search on google about K&R erata. – Michi Apr 16 '16 at 17:24
  • You should use a proper compiler which does inform you about this =>> `error: conflicting types for ‘func` – Michi Apr 16 '16 at 17:27

1 Answers1

3

How does the below code gets interpreted as per K&R C?

As code with a syntax error. K&R C does neither know about prototypes nor the void keyword (both were introduced with C89), so it is a syntax error.

Starting with C89, conflicting declarations are a constraint violation (fancy words for error) that must be diagnosed.

Jens
  • 69,818
  • 15
  • 125
  • 179