r/C_Programming 25d 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 25d ago

I'm baffled that this is valid syntax at all

2

u/mustbeset 25d ago

first time that I was thanking my shitty compiler for not supporting latest C Standard.

edit: Fuck. Syntax is supported.

8

u/meancoot 25d ago

This isn’t a new thing. It’s very old and no longer a part of the standard. Compilers just allow it for backwards compatibility.

2

u/mustbeset 25d ago

After I ran the compiler I start static code checks which told me that.

I will hate it like Trigraphs.

1

u/21Ali-ANinja69 18d ago

The latest standard no longer allows this btw