13

Day by day I realise that I don't know C

Comments
  • 4
    I think it should be
    double max (double x, double y) {
    ...

    And ℅Lf in printf.
  • 3
    I'm amazed that gcc compiled without any errors. But g++ shows the error.
  • 1
    @lucas22 I'm not trying to debug it. I'm trying to figure out why this works.
  • 0
    @perix2 if I use int, I'll get a single output which will be 20 due to float to int implicit conversion. But I'm getting some garbage values each time I try to execute it.
  • 0
    @prabhakaran9397 that's probably because you're not actually declaring x and y, so what the compiler does is get random recent values that sometimes happen to be the correct ones. If there's one thing I've learned with C is that GCC warnings sucks and common errors are inexistent. I always use g++ or some other like clang.
  • 0
    Where did you learn that? Not declaring the type of the parameters predates the ANSI standard. That's really archaic, nobody declares their parameters like that any more, not for a long time. Last time I saw code like that it was from the 80s. I'm kind of surprised the compiler didn't warn about it.
  • 1
    Don't use undefined behaviour. If it happens, the compiler would not be violating the standard if it wiped your hard drive when you ran it.
  • 0
    Default int as said by @QoolQuy2000. the compiler feeds data laid out like a float in memory to a function that treats the same memory as an int.

    Even if you don't use the stdlib, C++ keeps you safer by default.

    And no matter which, always -Wall
  • 0
    ¯\_(ツ)_/¯ you coming from python or something ?
  • 0
    @QoolQuy2000 while learning compiler design!
  • 0
    @Tychus trying to learn how GCC was designed and how it differs from G++ in parser phase
  • 0
    @TktStatusPICNIC wondering why they allowed those stupid stuffs!!!
Add Comment