Live data from Hacker News

Essential C (2003) [pdf]

cslibrary.stanford.edu

1–10 of 84 posts

Re: Essential C (2003) [pdf]

#4

This, paired with their Pointers and Memory [1] guide are how I learned C in college. They're both pretty short and to the point, I would highly recommend. [1] http://cslibrary.stanford.edu/102/PointersAndMemory.pdf

That and other useful links are listed in the parent page of this pdf.

http://cslibrary.stanford.edu/101/

Re: Essential C (2003) [pdf]

#5
> Relying on the difference between the pre and post variations of these operators is a classic area of C programmer ego showmanship.

Ugh. He's talking about inline use of post-increment and pre-increment (i.e. x++ and ++x) here. This is perfectly readable to a C programmer, and sidestepping them actually makes the code harder to understand.

Re: Essential C (2003) [pdf]

#6

> Relying on the difference between the pre and post variations of these operators is a classic area of C programmer ego showmanship. Ugh. He's talking about inline use of post-increment and pre-increment (i.e. x++ and ++x) here. This is perfectly readable to a C programmer, and sidestepping them actually makes the code harder to understand.

Can you give an example where not using them 'inline' makes code harder to understand?

Re: Essential C (2003) [pdf]

#7

> Relying on the difference between the pre and post variations of these operators is a classic area of C programmer ego showmanship. Ugh. He's talking about inline use of post-increment and pre-increment (i.e. x++ and ++x) here. This is perfectly readable to a C programmer, and sidestepping them actually makes the code harder to understand.

Can you give an example where not using them 'inline' makes code harder to understand?

You can't beat

    return x++;
:)

Re: Essential C (2003) [pdf]

#8

> Relying on the difference between the pre and post variations of these operators is a classic area of C programmer ego showmanship. Ugh. He's talking about inline use of post-increment and pre-increment (i.e. x++ and ++x) here. This is perfectly readable to a C programmer, and sidestepping them actually makes the code harder to understand.

Can you give an example where not using them 'inline' makes code harder to understand?

Consider the idiomatic way of interating backward through a array:

  for(i=n; i-- > 0 ;)
    { /* operate on a[i] */ }
converting i--; to a statement at the start of block makes it less clear that it's part of the iteration idiom rather than a ad hoc adjustment that's specific to this particular logic. There are other examples, but they're either more involved or statementification is less obviously wrong.

Re: Essential C (2003) [pdf]

#10

Earlier quoted context omitted.

Can you give an example where not using them 'inline' makes code harder to understand?

Consider the idiomatic way of interating backward through a array: for(i=n; i-- > 0 ;) { /* operate on a[i] */ } converting i--; to a statement at the start of block makes it less clear that it's part of the iteration idiom rather than a ad hoc adjustment that's specific to this particular logic. There are other examples, but they're either more involved or statementification is less obviously wrong.

That's the idiomatic way? Cool. The more straightforward-looking way,

    for(i = n-1; i >= 0; i--)
        { /* operate on a[i] */ }
breaks if i is unsigned, like a size_t.
Post reply on HN