DEV Community

Cover image for Decoding Compiler Confusion: Why the error messages of C are so confusing
joyeta jahan
joyeta jahan

Posted on

Decoding Compiler Confusion: Why the error messages of C are so confusing

Note: These notes, insights and questions are from my CS50 journey (lecture 2: Array)

Notes:

  • Syntax: Rules specific to a programming language that we need to follow if we want to write code in that programming language (aka give the computer instructions)
  • Bugs: Mistakes in code
  • Syntax error: The message compiler (the software that turns programming instructions into machine code aka 0’s and 1’s) throws if the coder has broken any syntax rules of the programming language
  • Error: The message compiler throws when something is wrong with the syntax
  • Logical error: An error (techincally bug) where the program runs (aka the compiler doesn’t throw an error) however it still does not behave the way it should.

Questions and Insights:

  • What happens if I add cs50 get_string function taking a string input from a user to an int variable? - throws an error (incompatiable pointer type)
  • If I have only stdio file as header file but call a function from a different file then the compiler throws a weird error. It looks for the most similar looking function (according to the name of the called function) in the header file mentioned (stdio) and says maybe you meant this…? In that case the compiler will not tell you straightforward what mistake you made cause it does not know if you meant to call another function from another file. It doesn’t know the other function even exists. So it looks for the closest looking functino however still throws the unindentifier error. That should be a tell.

To sum up, C errors are confusing because it never really tells you what you did wrong, it only tells what it is missing in order to execute a line of code and that can seem cryptic sometimes

Top comments (0)