• sweng@programming.dev
    link
    fedilink
    arrow-up
    88
    arrow-down
    2
    ·
    edit-2
    10 months ago

    You would think so, but int* a, b is actually eqivalent to int* a; int b, so the asterisk actually does go with the name. Writing int* a, *b is inconsistent, so int *a, *b is the way to go.

    • newH0pe@feddit.de
      link
      fedilink
      arrow-up
      57
      arrow-down
      1
      ·
      10 months ago

      Yeah, and I’d say that’s a design flaw of the language as it is unintuitive behaviour.

    • Slotos@feddit.nl
      link
      fedilink
      arrow-up
      38
      ·
      10 months ago

      When people say “pointers are hard”, they mean “I have no idea where the star goes and now an ampersand is also implicated”.

      • T156@lemmy.world
        link
        fedilink
        English
        arrow-up
        24
        ·
        10 months ago

        That’s the part where you give up and randomly shove/unshove symbols in until the code works.

        • CanadaPlus
          link
          fedilink
          English
          arrow-up
          5
          ·
          10 months ago

          I’ve definitely never been guilty of this. /s

    • blackstrat@lemmy.fwgx.uk
      link
      fedilink
      arrow-up
      25
      ·
      10 months ago

      While technically true, that’s also one of the worst ‘features’ of the language and I personally consider it a bug in the language. Use two lines and make it clear and correct.

    • Gladaed@feddit.de
      link
      fedilink
      arrow-up
      17
      arrow-down
      2
      ·
      10 months ago

      Don’t declare more than 1 pointer per line. This resolves that, badly.

    • CanadaPlus
      link
      fedilink
      English
      arrow-up
      8
      ·
      10 months ago

      Alright, I’ll never, ever write something this way now. Good to know.