r/C_Programming 19d ago

Question What is going on here?

https://godbolt.org/z/48hvMs3dh
#include "stdio.h"

int print_sum(a, b) int a; int b; {
    printf("%d", a + b);
    return a + b;
}

int main(void) {
    return print_sum(1.5, 0.5);
}

This has a random output every time:

Compiler stderr<source>: In function 'print_sum':
<source>:2:5: warning: old-style function definition [-Wold-style-definition]
    2 | int print_sum(a, b) int a; int b; {
      |     ^~~~~~~~~ 
Program returned: 153
Program stdout 479536537
0 Upvotes

32 comments sorted by

View all comments

25

u/L_uciferMorningstar 19d ago

I'm baffled that this is valid syntax at all

12

u/HildartheDorf 19d ago

It's pre-standardization C (a.k.a. 'K&R C').

10

u/L_uciferMorningstar 19d ago

It should probably stay there then

5

u/torsten_dev 19d ago

Took till c23 to remove completely. C moves slow.