C C compiling differently in 13.3 versus 13.2

Hija,

13.3 does not compile, apparently due to patches of mine that did work in 13.2.
Still investigating...
 
Seems I found the reason for this one.

K&R said, "void" can only be the return type of a function, it must not be a parameter type. So functions were written:
Code:
void func() { whatever; }

Then somewhere was said, in the declaration a function with no parameters must be declared as void. So it was like that:
Code:
void func(void);
void func() { whatever; }

And that did work up to 13.2. Now it doesn't. Apparently it does now want "void" everywhere.
 
K&R was fairly seriously lacking in terms of type safety.

void func(void) in C is the equivalent of void func() in C++, a function taking no arguments. In both cases it is a prototype.

void func() in C is a function that takes any number and any type of arguments. It is only a declaration ("func is a function"), not a prototype ("func is a function taking such and such arguments"). It relies on programmer skill to have the same formal and actual arguments. If the programmer gets it wrong the compiler (and the link editor) can't produce an error message, and a runtime crash is likely.
 
K&R was fairly seriously lacking in terms of type safety.
You know, to get things going at first we assembled the hexcodes manually. Then we got an assembler. When C appeared, it was a great improvement - and you could still do the things you did before. :)
So what would type safety mean when you're used to arranging individual bits&bytes anyway?

void func() in C is a function that takes any number and any type of arguments. It is only a declaration ("func is a function"), not a prototype ("func is a function taking such and such arguments"). It relies on programmer skill to have the same formal and actual arguments. If the programmer gets it wrong the compiler (and the link editor) can't produce an error message, and a runtime crash is likely.
Thanks for the clarification. I'll adapt. :)
 
void func(void) in C is the equivalent of void func() in C++, a function taking no arguments. In both cases it is a prototype.
If I remember that correctly, no.
In C++, void foo() is equivalent to void foo(...), while meaning void foo(void) in C (my knowledge is likely outdated, it has been decades since I contributed to a C++ compiler). In C++, the argument list gets encoded into the symbol and you hit a link error. In C, not so. Where PMc is correct is that void can not be a named paramete. So no void foo(void uninteresting, int fd).
 
If I remember that correctly, no.
In C++, void foo() is equivalent to void foo(...), while meaning void foo(void) in C (my knowledge is likely outdated, it has been decades since I contributed to a C++ compiler). In C++, the argument list gets encoded into the symbol and you hit a link error. In C, not so. Where PMc is correct is that void can not be a named paramete. So no void foo(void uninteresting, int fd).

No, you don't remember correctly.

The ... means variadic arguments, which exist in both C and C++. See https://en.cppreference.com/w/cpp/language/variadic_arguments.

Take a look at this example on godbolt https://godbolt.org/z/5YdMd4bG6

It compiles with no warnings with the default arguments. If you remove the function declaration you will get a warning about foo being implicitly declared. If you make the declaration a prototype then it will fail to compile.

C++ has never allowed nonsense like this.
 
Back
Top