1. 31
  1.  

  2. 4

    Exegesis is a great word here that I think I’ll add to my lexicon.

    1. 4

      The Practice of Programming is a great book. It contains everything I remember learning in my 4 year CS degree, so I often tell programmer without a CS degree to just read it instead and save the money.

      1. 1

        I wonder why “c”, in the original code, is an int rather than a char.

        1. 2

          Since matchstar() is used in matchhere() before it is declared, there’s an implicit declaration of it with unspecified parameters (though this officially ended in C99, it’s still just a warning in gcc, and the book was written in 1998). Arguments to a function declared like that undergo integer promotions, so char promotes to int (the standard calls these “default argument promotions”). A char c parameter would have been incorrect, see the error on Godbolt.

          As for why it’s written that way, probably just force of habit, being used to not forward declaring functions unless absolutely necessary. If matchstar() had come before matchhere(), then char c would have typechecked ok, as would int c, but this order doesn’t read as nicely.

          Final note (sorry for editing this so much): The compiler just happens to catch char because a function taking a char can never possibly be called correctly via an implicit declaration (since a char argument will always promote to an int) and it’s in the same compilation unit. If it was another type without a default promotion, like say long long, things may go subtly wrong with no warning (pre-C99) if a long long isn’t actually passed in.

          1. 1

            Interesting, thank you!