{"id":7,"date":"2015-07-09T19:11:31","date_gmt":"2015-07-09T18:11:31","guid":{"rendered":"http:\/\/watchdiana.fail\/blog\/?p=7"},"modified":"2015-07-09T19:11:31","modified_gmt":"2015-07-09T18:11:31","slug":"learn-c-the-hard-way-i-do-everything-the-hard-way","status":"publish","type":"post","link":"https:\/\/watchdiana.fail\/blog\/2015\/07\/09\/learn-c-the-hard-way-i-do-everything-the-hard-way\/","title":{"rendered":"Learn C the Hard Way &#8211; I do everything the hard way"},"content":{"rendered":"<p>For those joining me in my world record yak shaving attempt, today I started poking at Learn C The Hard Way by Zed Shaw. It&#8217;s currently in its beta form, as he&#8217;s writing it in public so people can look and learn and proof-read, and I have a reason to learn enough C to get by. Sparky, the Spark Eroder, needs an output method to help me understand what&#8217;s going on in his insides. I can&#8217;t afford an oscilloscope, so a \u00a33 microprocessor is going to do the job.<\/p>\n<p>I say &#8216;a&#8217; microprocessor, but when I bricked the first, I ordered two more. If I&#8217;d bricked an oscilloscope, two more would have come in beyond budget.<\/p>\n<p>So, Zed has written up the two cases of Debian and RPM based Fedora, for the installation of what I&#8217;ll need. I work on Arch. There are reasons. They are not and can never be adequate reasons, but I&#8217;m sticking to them. So, the first thing I did was <a href=\"http:\/\/c.learncodethehardway.org\/book\/ex1.html\" target=\"_blank\">Exercise 1<\/a>, to see what would break. If I could make Ex 1 work, then I&#8217;d be set up right. If not, I&#8217;d have error messages.<\/p>\n<p>I had error messages!<\/p>\n<pre>ex1.c: In function 'main':\nex1.c:3: warning: implicit declaration of function 'puts'<\/pre>\n<p>Well, he explains this in the Ex 1 page &#8211; I&#8217;ve got flags set that will show errors. This one is a warning, and if I were on Debian or Fedora or in fact anything sane, it (probably) wouldn&#8217;t be a problem. But I&#8217;m not, and it is. So now I have to work out WTF the flags have to be. He can show me how to turn the flags \/on\/ and break things. I&#8217;m looking to turn the flags \/off\/ and mend things, or at least suppress them so I live in bliss and ignorance.<\/p>\n<p>Turning flags off in the future is probably a bad idea, and I&#8217;m going top be keeping them on in general, so if I run into this again I can flag it up, but I want to know how it&#8217;s going wrong. It also meant I didn&#8217;t type the version with the flags turned on.<\/p>\n<pre>$ man make<\/pre>\n<p>It seems that there&#8217;s a &#8211;warn-undefined-variables flag, but I can&#8217;t work out how to turn it off. There&#8217;s also a &#8211;touch flag, which is interesting. It&#8217;ll just poke (and possible create, I wasn&#8217;t doing more than skimming) files so they have updated timings for when I want to make a latest version of a set of files. That&#8217;s probably not useful for me yet, but the notion that<\/p>\n<pre>make<\/pre>\n<p>is so powerful is written all over the manual file. I can define different files as the ones to use, regardless of which are most recent, and I can deliberately override dependencies. So that tells me that make handles dependencies and stuff like that.<\/p>\n<p>On with the show. I can make, and use, &#8216;ex1.c&#8217;. It prints &#8216;Hello World.&#8217;. It&#8217;s a capital letter on the second word because that&#8217;s how I roll. Oddly, I&#8217;ve found that the tighter my copying of code gets, and the more I&#8217;m concentrating, the more likely I am to typo in the parts where there&#8217;s no penalty for error.<\/p>\n<p>Extra Credit:<\/p>\n<p>I didn&#8217;t edit the original exercise file. I made a second file so I&#8217;d be typing the same things again, so I&#8217;ve got ex1a as well as ex1. I&#8217;m pretty sure that&#8217;s better, as I can compare programs if I have to.<\/p>\n<p>I worked out what stdio has to stand for. It&#8217;s not short for Studio. It means &#8216;standard in-out&#8217;. The &#8216;.h&#8217; means it&#8217;s a header file. I looked up the second bit. The first bit I knew through failing repeatedly at Linux everything, and I&#8217;m OK with that.<\/p>\n<p>I managed to get a segmentation fault by using &#8216; instead of &#8221; as line breaks. I also need a work-around for my American keyboard which doesn&#8217;t play nicely with my locale settings. I&#8217;m going to have to give up the \u00a3 to get a # and a working pipe that doesn&#8217;t need five key presses and a swift prayer.<\/p>\n<pre>man 3 puts<\/pre>\n<p>&#8211; The &#8216;3&#8217; means it&#8217;s in part 3 of the linux user manual, which deals with C library functions. So,<\/p>\n<pre>#include<\/pre>\n<p>means you&#8217;re explicitly declaring the existence of puts() in the library you include, instead of implicitly calling it and relying on the compiler to make up for your error.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For those joining me in my world record yak shaving attempt, today I started poking at Learn C The Hard Way by Zed Shaw. It&#8217;s currently in its beta form, as he&#8217;s writing it in public so people can look and learn and proof-read, and I have a reason to learn enough C to get [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[7,9,10,11,12,13],"class_list":["post-7","post","type-post","status-publish","format-standard","hentry","category-coding","tag-c","tag-coding","tag-fun-with-arch-linux","tag-learn-c-the-hard-way","tag-sparky","tag-things-i-do-because-im-stubborn","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/posts\/7","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/comments?post=7"}],"version-history":[{"count":0,"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/posts\/7\/revisions"}],"wp:attachment":[{"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/media?parent=7"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/categories?post=7"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/tags?post=7"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}