Live data from Hacker News

Tenacious C: Cool C IDE

tenaciousc.com

21–30 of 43 posts

Re: Tenacious C: Cool C IDE

#21
Neat, but I question the Windows only choice here. A lot of C programmers are developing on a *nix platform. But I see this as being more useful for students learning C and memory management. It's a neat project and might recommend it to students but I'll stick to vim, myself.

Re: Tenacious C: Cool C IDE

#22
post #20

Good top post on the blog page, made me lol: 'I like C, but I have to admit that, sometimes, “The Old Man of Programming” can be a bit of a killjoy. This is one of the most exciting eras in computer history, but lately, C’s acting like he doesn’t even want to have a good time. While the cool kids like Ruby and Haskell are living it up, C’s over in the corner obsessing over bits and bytes and memory alignment and poin…

The blog post is excellent. It led me to this: http://www.lysator.liu.se/c/duffs-device.html I've programmed in C a fair amount, but I am incapable of understanding the construct contained therein. Specifically, the interaction of the switch and the loop and all those fall-through cases. I would absolutely love it if some C-guru hn-er could describe it in layman's terms?

It's really less complex than it appears, especially once you grok that switch/case is just a computed goto; cases are just labels.

So, the idea behind Duff's Device is just to unroll a loop, dealing in an elegant (some would say abhorrent - they're wrong) way with the "leftover" portion.

So, the canonical Duff's is copying shorts, with the copy loop unrolled to eight copy statements inside the loop. If you want to copy, say 47 shorts, the loop would need to iterate five times, and there would be seven shorts left to copy.

Duff's uses the switch to jump into the middle of the loop just far enough to copy those seven leftover shorts (47 % 8 = 7). The do-while then proceeds to run through the five full iterations.

Modern compilers will do that for you now, though there are still applications for similar code.

Hope that helps.

Re: Tenacious C: Cool C IDE

#23
post #20

Good top post on the blog page, made me lol: 'I like C, but I have to admit that, sometimes, “The Old Man of Programming” can be a bit of a killjoy. This is one of the most exciting eras in computer history, but lately, C’s acting like he doesn’t even want to have a good time. While the cool kids like Ruby and Haskell are living it up, C’s over in the corner obsessing over bits and bytes and memory alignment and poin…

The blog post is excellent. It led me to this: http://www.lysator.liu.se/c/duffs-device.html I've programmed in C a fair amount, but I am incapable of understanding the construct contained therein. Specifically, the interaction of the switch and the loop and all those fall-through cases. I would absolutely love it if some C-guru hn-er could describe it in layman's terms?

I made you a crappy flowchart that demonstrates Duff's Device (with 4 cases rather than 8 since I'm lazy):

http://i.imgur.com/L73ai.png

The basic idea is that the switch jumps into the body of the loop somewhere, after that it can do blocks of the same function over and over without having to do the conditional check to exit the loop as often.

For example, if you're copying memory, and you want to copy say, 9 bytes then you'd jump into the loop, copy 1 byte, run the conditional check, realize that you're not done, and then copy 8 more bytes, run the conditional check, realize you're done and exit the loop. For the 8*n times you run through the "unrolled" loop after that first pass through, there are a lot less conditional branches, so many processors can execute those instructions faster. That's the idea, anyway.

Re: Tenacious C: Cool C IDE

#24

What a joke. Things like this – and the rhetoric on his site – make systems programming look like more of a dark art than it actually is. If you're a programmer, should know how your computer works; if pointers are too "hard" for you, you're in the wrong business. You're settling for mediocrity and belittling your own intelligence by assuming you're not capable of tackling this stuff the same way everyone else has.

I dunno, I have a lot respect for people who take difficult concepts and try to make them easier to grasp. Teachers are more valuable than belittlers. "This isn't hard" is not a lesson plan or a path to enlightenment.

I also have a lot of respect for people who are willing to teach. But I don't respect teachers that speak of these concepts like they're magic that no mere mortal can understand. This is stuff that everyone can know -- and should know -- and needs to be treated like learning arithmetic, not tensor calculus.

Re: Tenacious C: Cool C IDE

#25
Of course, if you learned assembly first instead of Java or somesuch, pointers make 100% intuitive sense, and if you didn't grok them completely you wouldn't have been able to write your first program.

Re: Tenacious C: Cool C IDE

#26
post #20

Good top post on the blog page, made me lol: 'I like C, but I have to admit that, sometimes, “The Old Man of Programming” can be a bit of a killjoy. This is one of the most exciting eras in computer history, but lately, C’s acting like he doesn’t even want to have a good time. While the cool kids like Ruby and Haskell are living it up, C’s over in the corner obsessing over bits and bytes and memory alignment and poin…

The blog post is excellent. It led me to this: http://www.lysator.liu.se/c/duffs-device.html I've programmed in C a fair amount, but I am incapable of understanding the construct contained therein. Specifically, the interaction of the switch and the loop and all those fall-through cases. I would absolutely love it if some C-guru hn-er could describe it in layman's terms?

The other two comments are right, but the context you might be missing is why you would unroll a loop. Due to cache behavior (and other low-level details), doing something eight times and then checking if it needs to be done another eight times has less overhead than checking after each loop iteration. Why eight? It was probably a sweet spot in time vs. code size, at some point. (Processor caches are larger now.)

Duff's device just gets the (remainder of N/8) steps out of the way the first time through, then drops down to looping eight at a time. If it seems more complicated than that, you're probably overthinking it. It's "just" a creative abuse of C syntax, a bunch of offsets and gotos.

Sometimes low-level optimization like this makes a huge difference, but make sure it's a hotspot first, and that the compiler isn't already doing those things for you. Measurements will keep you objective.

Also, if you're doing a lot with C, check out Lua!

Re: Tenacious C: Cool C IDE

#27
post #16
post #14

Earlier quoted context omitted.

> a web-based GUI wrapper ...why would you want to do that for a C debugger?

It's just that you write it once and it can run anywhere without "installing" many dependencies other than a browser. No fugly GUIs, no inconsistencies, etc. By web-based I didn't mean it to be on the Internet.

So basically, "web-based" is the new portable GUI library.

Re: Tenacious C: Cool C IDE

#29
post #23
post #20

Earlier quoted context omitted.

The blog post is excellent. It led me to this: http://www.lysator.liu.se/c/duffs-device.html I've programmed in C a fair amount, but I am incapable of understanding the construct contained therein. Specifically, the interaction of the switch and the loop and all those fall-through cases. I would absolutely love it if some C-guru hn-er could describe it in layman's terms?

I made you a crappy flowchart that demonstrates Duff's Device (with 4 cases rather than 8 since I'm lazy): http://i.imgur.com/L73ai.png The basic idea is that the switch jumps into the body of the loop somewhere, after that it can do blocks of the same function over and over without having to do the conditional check to exit the loop as often. For example, if you're copying memory, and you want to copy say, 9 bytes t…

That is a really good description (and I love the `crappy flowchart`, thanks). But I think what I'm mostly taking away from this is that my brain struggles with the more serious aspects of C-style imperative programming.

Re: Tenacious C: Cool C IDE

#30
post #20

Earlier quoted context omitted.

The blog post is excellent. It led me to this: http://www.lysator.liu.se/c/duffs-device.html I've programmed in C a fair amount, but I am incapable of understanding the construct contained therein. Specifically, the interaction of the switch and the loop and all those fall-through cases. I would absolutely love it if some C-guru hn-er could describe it in layman's terms?

It's really less complex than it appears, especially once you grok that switch/case is just a computed goto; cases are just labels. So, the idea behind Duff's Device is just to unroll a loop, dealing in an elegant (some would say abhorrent - they're wrong) way with the "leftover" portion. So, the canonical Duff's is copying shorts, with the copy loop unrolled to eight copy statements inside the loop. If you want to c…

Okay, this definitely helps but I'm still struggling (sorry), I'm probably focusing too much on minutiae but:

* At the static level, what does it mean to start the loop at `case 0` then fall through to the termination of the loop? Part of me is surpisued that it even compiles (again, sorry); it's like the mechancis of the loop itself become dependent on the runtime input, at which point my brain begins to frazzle gently.

* Why is the `to` pointer never incremented? Is that some super-clever thing that I'm not seeing or is it just left out of the algorithm for clarity?

(EDIT: Formatting)

Post reply on HN