News for hackers. Stuff that matters.
Re:Everything I wish I knew when learning C by torstenvl on Monday November 28, 2022 @08:55AM (#33773675)
I like that a lot! However, it makes things like

    int *x = &a;
a bit more confusing/inconsistent.
Re:Everything I wish I knew when learning C by pif on Monday November 28, 2022 @09:44AM (#33774186)
Not at all!

a is int; &a is pointer to int; x is pointer to int; *x in again int.

Re:Everything I wish I knew when learning C by fwip on Monday November 28, 2022 @12:34PM (#33776572)
Gotcha, so it's kind of like:

    int (*(x = &(a)));
    i    i p   p i   // i means int, p means pointer
Re:Everything I wish I knew when learning C by thomastjeffery on Monday November 28, 2022 @01:49PM (#33777780)
I prefer to think of it as

    (int *) x = &(a);
     i   p  p   a i // a means address       
    
Which is why I prefer to write

    int* x = &a;
"integer pointer" named "x" set to address of integer "a".

---

As a sibling comment pointed out, this is ambiguous when using multiple declaration:

    int* foo, bar;
The above statement declares an "integer pointer" foo and an "integer" bar. It can be unambiguously rewritten as:

    int bar, *foo;
But multiple declaration sucks anyway! It's widely accepted good practice to set (instantiate) your variables in the same statement that you declare them. Otherwise your program might start reading whatever data was lying around on the stack (the current value of bar) or worse: whatever random memory address it refers to (the current value of foo).
Re:Everything I wish I knew when learning C by fwip on Saturday December 03, 2022 @04:13PM (#33847415)
Thanks :)