Reader small image

You're reading from  Learn C Programming. - Second Edition

Product typeBook
Published inAug 2022
PublisherPackt
ISBN-139781801078450
Edition2nd Edition
Right arrow
Author (1)
Jeff Szuhay
Jeff Szuhay
author image
Jeff Szuhay

Jeff Szuhay is the principal developer at QuarterTil2 which specializes in graphics-rich software chronographs for desktop environments. In his software career of over 35 years, he has engaged in a full range of development activities from systems analysis and systems performance tuning to application design, from initial development through full testing and final delivery. Throughout that time, he has taught computer applications and programming languages at various educational levels from elementary school students to university students, as well as developed and presented professional, on-site training.
Read more about Jeff Szuhay

Right arrow

Learning to experiment with code

Now that we have gotten our basic program to work (woo-hoo!), we can turn our attention to learning how to intentionally break it (ouch!). This is so that we can learn more about what the compiler is trying to tell us. What it is telling us isn't always clear, especially while we are learning.

Once you have mastered the language, there would be little need to do this (yay!). However, while we are learning the language, becoming familiar with the various kinds of compiler error messages is essential and, ultimately, will save us many hours/weeks of debugging, which might have been prevented early on in the iterative program development cycle. Please do not skip this essential step as you learn C as it will save you many hours/weeks.

So, using the full program development cycle outlined earlier, inject the following errors into your source file. When you see the error messages, try to correlate them with what you just did to cause them. After each one, correct the error and recompile it to verify the fix:

  • Remove { from hello2.c. Save it and compile it. What errors does the compiler give?
  • Put { back in its appropriate place and remove }. What errors does the compiler give?
  • There are three other paired punctuation marks: <> and (), which occur twice, and "". What errors does the compiler give when you remove the opening of the pair and the closing of the pair? Put them back after each experiment.
  • Remove ; from either line. What error messages does the compiler give?
  • Comment out the return 0; line. What error messages does the compiler give?
  • Change int main() to int MAIN(). What does the compiler tell you?
  • Similarly, change printf( to printout(. With this error, you should be able to see what linker messages look like.
  • Now, comment out #include <stdio.h>. You should also see linker errors telling you they can't find the printf() function.
  • Return hello2.c to its original state. Compile, run, and verify the program is both correct and complete.

If you get more than 23,000 lines of error messages from the compiler, I would really like to know. Please email me with the details of your experiments.

Previous PageNext Page
You have been reading a chapter from
Learn C Programming. - Second Edition
Published in: Aug 2022Publisher: PacktISBN-13: 9781801078450
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Jeff Szuhay

Jeff Szuhay is the principal developer at QuarterTil2 which specializes in graphics-rich software chronographs for desktop environments. In his software career of over 35 years, he has engaged in a full range of development activities from systems analysis and systems performance tuning to application design, from initial development through full testing and final delivery. Throughout that time, he has taught computer applications and programming languages at various educational levels from elementary school students to university students, as well as developed and presented professional, on-site training.
Read more about Jeff Szuhay