:: Re: [DNG] Learning C
Top Pagina
Delete this message
Reply to this message
Auteur: nick
Datum:  
Aan: dng
Onderwerp: Re: [DNG] Learning C


On the subject of Kelley and Pohl they also have a book called "A Book on C" which I was impressed with back in the day. I mentioned it in my earlier message but I thought then that it was by Schildt, after I wrote I searched it and found it was by Kelley and Pohl. Is C by dissection a later version of same or does it fill a different niche?



To be honest I have not consumed C learning materials in decades so it's not surprising I'm out of date. I did teach C at university level to earn money as a postgrad, but I didn't think much of the textbook. It was written by the professor, and obviously he made it a requirement to make sure he maximized his royalties!! Well many students had illegal photocopies, but they knew they would have to conceal them well from the professor during the labs, haha... I still had my copy from when I did the course, but around week 6 I lent it to a student who then disappeared. So for the rest of the course i went to the library each week to copy the questions.



It was nice of several commenters to list out a set of exercises! I recommend OP to follow those exercises, or at least find similar exercises in a textbook if the instructions were too terse to be followed by a novice.



I was interested to hear another commenter saying K&R was the worst resource to learn from. That may be so -- it was fine when I used it, but then again, we had very few options in those pre internet days. I remember as a teenager i would regularly catch a train into the city to visit "the technical bookshop" or "mcgills" where the upstairs were devoted to computer books. Alas neither exists anymore. Many books were over $100 and you simply could not afford them especially as a teenager, so I would read as much as i could in situ about DOS internals or VGA registers or whatnot! I never dreamed it would be available for free later. I try to explain this to my kids and I get blank looks as they've always had Internet.



I still think the best way to really learn C in depth is to get ones hands dirty in early Unix. For example, by porting some of the early Unix tools like cp, mv or more complex ones like cc, ld, sh over to a modern system, you really gain an appreciation of the finer points of C and its environment (Unix, Windows...). Or look into pcc (Portable C Compiler by Steve Johnson) and be amazed, although the code is actually a bit of a dog's breakfast compared with Ritchie's PDP-11 original.



Finally, to the commenter who suggested ANSI C (or more properly ANSI C89 / ISO C90 ??) may be out of date: I don't think so. It's not like C++ where the language gets radically changed with each revision. The committee is really very conservative. The only big change they made was with VLAs and honestly this change was probably a mistake -- they also realized this and backtracked by making it optional in the next revision. Well, supposedly the next one (C24?) makes a watered down VLA subset be mandatory and I think there is probably some sense in this given it will only apply to parameter passing (of arrays) and this has traditionally been a weak point with C.



Apart from that, the changes since ANSI are purely evolutionary and in fact good old ANSI C code will be accepted by any compiler today without excessive complaining and still do as good a job as it ever did. You may want to run without aliasing optimizations though if you're writing plain ANSI C code. Anyway, the only later feature that I really rely on is stdbool.h and you could create that yourself without any real issues:

typedef unsigned char bool;

#define false 0

#define true 1

(traditionally these were uppercase but the stdbool.h way is much easier on the eye).



cheers,

Nick



Ps. Keep it coming folks. I feel like less of an ancient curmudgeon when surrounded by same ;)








>
> On 28 Sept 2024 at 3:19 am, dng-request <dng-request@???> wrote:
>
>
> Send Dng mailing list submissions to
> dng@???
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng
> or, via email, send a message with subject or body 'help' to
> dng-request@???
>
> You can reach the person managing the list at
> dng-owner@???
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Dng digest..."
>
>
> Today's Topics:
>
> 1. Re: What browser? (WAS: Re: So what desktop do you use?)
> (Kevin Chadwick)
> 2. Re: Replacing CUPS with lprng? (sawbona@???)
> 3. Re: Replacing CUPS with lprng? (Peter Duffy)
> 4. Re: devuan-based vps offerings (Peter Duffy)
> 5. Re: Learning C (Peter Duffy)
> 6. Re: Replacing CUPS with lprng? (Daniel Abrecht)
> 7. Re: Replacing CUPS with lprng? (Joel Roth)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Fri, 27 Sep 2024 15:35:34 +0100
> From: Kevin Chadwick <kc-devuan@???>
> To: dng@???
> Subject: Re: [DNG] What browser? (WAS: Re: So what desktop do you
> use?)
> Message-ID: <1ec08e04-1774-4921-8c60-e75d4c4b1442@???>
> Content-Type: text/plain; charset=UTF-8
>
> On 27/09/2024 15:24, al3xu5 via Dng wrote:
> > Please give me your opinion/advice...
>
> The concern with derivatives is that security updates are likely delayed.
>
>
> ------------------------------
>
> Message: 2
> Date: Fri, 27 Sep 2024 11:38:17 -0300
> From: sawbona@???
> To: Johan Helsingius via Dng <dng@???>
> Subject: Re: [DNG] Replacing CUPS with lprng?
> Message-ID: <66F6C359.9829.EF57D@???>
> Content-Type: text/plain; charset=US-ASCII
>
> Hello:
>
> On 27 Sep 2024 at 14:40, Johan Helsingius via Dng wrote:
>
> > In view of the CUPS vulnerability ...
> For the moment (and from what *I* have undesrtood) it would seem that
> disabling / uninstalling [cups-browsed] would be enough.
>
> Yes?
>
> Also, you may want to consider a 'wait and see' period till Linuxland
> can evaluate what the eventual fix/patch brings along.
>
> Of course, the above if you *need* network printing, but if not ...
> ... does CUPS actually represent a problem?
>
> Best,
>
> A.
>
>
> ------------------------------
>
> Message: 3
> Date: Fri, 27 Sep 2024 16:55:35 +0100
> From: Peter Duffy <peter@???>
> To: dng@???
> Subject: Re: [DNG] Replacing CUPS with lprng?
> Message-ID:
> <3df4afd3bf93635b123c998ae1ebfb623a82d1e6.camel@???>
> Content-Type: text/plain; charset="UTF-8"
>
> My impression so far is that the risk to "leaf nodes" of the internet
> (ones behind routers provided by ISPs, and including firewalls and
> NATting) ***should*** be minimal - as UDP port 631 should be blocked by
> default (if not, the ISP needs kicking), and no one in their right mind
> would expose it via a port-forwarding hole through the firewall. At
> least, I can't imagine a valid reason for doing so.
>
> I'll bet that there was a lot of frantic disabling and removing of
> cups-browsed last night, by the admins of servers in the guts of the
> internet. (So glad I retired last year :) )
>
> It occurs to me that the biggest risk to internet end-users would be if
> a hacker managed to log in as a non-privileged user. This hole would
> probably be a relatively easy way to escalate privileges.
>
> It's certainly a very big and nasty hole. It'll be very interesting to
> see what can be done to patch it. Presumably it will involve making
> cups-browsed be much more picky about verifying the nature of things
> that connect to it.
>
> On Fri, 2024-09-27 at 11:38 -0300, altoid via Dng wrote:
> > Hello:
> >
> > On 27 Sep 2024 at 14:40, Johan Helsingius via Dng wrote:
> >
> > > In view of the CUPS vulnerability ...
> > For the moment (and from what *I* have undesrtood) it would seem that
> > disabling / uninstalling [cups-browsed] would be enough.
> >
> > Yes?
> >
> > Also, you may want to consider a 'wait and see' period till Linuxland
> > can evaluate what the eventual fix/patch brings along.
> >
> > Of course, the above if you *need* network printing, but if not ...
> > ... does CUPS actually represent a problem?
> >
> > Best,
> >
> > A.
> > _______________________________________________
> > Dng mailing list
> > Dng@???
> > https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng
>
>
>
>
> ------------------------------
>
> Message: 4
> Date: Fri, 27 Sep 2024 16:56:44 +0100
> From: Peter Duffy <peter@???>
> To: dng@???
> Subject: Re: [DNG] devuan-based vps offerings
> Message-ID:
> <0137ee8c0de9ed12a8e9112df3ab8a81b30018f0.camel@???>
> Content-Type: text/plain; charset="UTF-8"
>
> Daniel, thanks for that. Hetzner came up on some of my own google
> searches as a possibility: I will investigate further.
>
> On Thu, 2024-09-26 at 16:59 +0200, Daniel Klein wrote:
> > On 9/26/24 16:34, Peter Duffy wrote:
> >
> > > Does anyone have any suggestions or even recommendations for
> > > companies
> > > hosting or supporting devuan-based VPSs, or ones which offer
> > > debian-
> > > based VPSs which have been shown to be capable of being migrated to
> > > devuan? If necessary, I can roll my own iso image.
> >
> > Hetzner may be a good option. I used a debian install and migrated it
> > to
> > devuan many times you also could use your own isos.
> > They now have more locations outside of germany and even Europe. And
> > the
> > pricing is (from my viewpoint) very reasonable.
> >
> >
> > Daniel
> >
> > _______________________________________________
> > Dng mailing list
> > Dng@???
> > https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng
>
>
>
>
> ------------------------------
>
> Message: 5
> Date: Fri, 27 Sep 2024 17:42:19 +0100
> From: Peter Duffy <peter@???>
> To: dng@???
> Subject: Re: [DNG] Learning C
> Message-ID:
> <cfff1bf718c7b9d1a86812708e14b34e3c4ff80e.camel@???>
> Content-Type: text/plain; charset="UTF-8"
>
> Apropos books on C, here's my two-penny-worth:
>
> I'd always have Kernigan and Ritchie: "The C Programming Language" -
> admirably clear, concise and yet eminently readable. I'd also not be
> without the companion volume: Kernighan and Pike: "The Unix Programming
> Environment" - still one of the best introductions to Unix yet written,
> and most of it is still valid for linux.?(I get the impression that
> Brian Kernighan became the main communicator and documentor of the Unix
> project, although he is obviously a master programmer in his own right:
> he is the "k" in awk, as he was one of the three people who wrote it -
> the others were Alfred Aho and Peter Weinberger. Kernighan allegedly
> also came up with the name "Unix".)
>
> The fact is that, effectively, C was written in order for Unix to be
> rewritten in it. So it had to be enormously flexible, and closer to the
> assembly level than most high-level languages. That was a two-edged
> sword: it made the language unbelievably powerful and expressive - but
> also introduced a massive set of pitfalls for the unwary. It's
> trivially possible to write a C program (deliberately or accidentally)
> which will be happily swallowed by the compiler, but which when run
> will crash with "segmentation fault" or "bus error", or even worse, eat
> its way through all available RAM and cause the system to lock up. It's
> as though one first learns to program in C, and then starts to learn
> how to write a C program (bit like the strange experience where one
> passes the driving test, and then starts to learn how to drive).
>
> I've found three books which go into the pitfalls and gotchas in
> considerable depth, and which I wouldn't be without:
>
> Perry, John W. : C programming by example (PWS Publishing Company,
> Boston, MA.)
>
> van der Linden, Peter: Expert C Programming (Deep C secrets) (Prentice
> Hall) (title of one section: "Bus error, take the train")
>
> Kelley, Al & Pohl, Ira: C by dissection (Addison Wesley)
>
> Not sure whether these are still in print: if not, second-user copies
> will probably be available via amazon or abebooks. I can't really
> recommend one over the others - I've learnt a lot from all three, and
> they seem to complement each other to some extent. There are mentions
> of C++ here and there, but mostly as afterthoughts.
>
> On Tue, 2024-09-24 at 10:43 +0200, Didier Kryn wrote:
> > Le 24/09/2024 ? 04:05, o1bigtenor via Dng a ?crit?:
> > >
> > I consider the best way is to take lessons, and the second best way
> > is
> > to use a good book. A book about C only, not "C and C++".
> >
> > -- ??? Didier
> >
> > _______________________________________________
> > Dng mailing list
> > Dng@???
> > https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng
>
>
>
>
> ------------------------------
>
> Message: 6
> Date: Fri, 27 Sep 2024 19:11:37 +0200
> From: Daniel Abrecht <dng@???>
> To: dng@???
> Subject: Re: [DNG] Replacing CUPS with lprng?
> Message-ID: <fa65ebb3fb732298430e09675538006d@???>
> Content-Type: text/plain; charset=US-ASCII; format=flowed
>
> My current understanding of the CUPS thing is, the command is only
> executed if someone actually prints something on the malicious fake
> printer.
> So on machines nobody actually does print anything on, things should be
> fine.
> This is difficult to fix, as all parts work as designed, but together
> there is an issue. It's an integration problem, rather than one specific
> bug. There may be some of those too, but I'm sure regular bugs are going
> to be fixed soon enough.
>
> Just in case, I've removed cups-browsed. It seams my printer /
> printserver is still auto detected through avahi-daemon, though, so that
> may be another vector, but I don't know.
>
>
>
>
> ------------------------------
>
> Message: 7
> Date: Fri, 27 Sep 2024 07:19:16 -1000
> From: Joel Roth <joelz@???>
> To: dng@???
> Subject: Re: [DNG] Replacing CUPS with lprng?
> Message-ID: <20240927171916.dpzet2pythwd2un4@sprite>
> Content-Type: text/plain; charset=us-ascii
>
> Peter Duffy wrote:
> > My impression so far is that the risk to "leaf nodes" of the internet
> > (ones behind routers provided by ISPs, and including firewalls and
> > NATting) ***should*** be minimal - as UDP port 631 should be blocked by
> > default (if not, the ISP needs kicking), and no one in their right mind
> > would expose it via a port-forwarding hole through the firewall. At
> > least, I can't imagine a valid reason for doing so.
>
> I was considering that many off-the-shelf routers may be running CUPS,
> even with no printer connected.
>
> --
> Joel Roth
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Dng mailing list
> Dng@???
> https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng
>
>
> ------------------------------
>
> End of Dng Digest, Vol 120, Issue 47
> ************************************
>