37
you are viewing a single comment's thread
view the rest of the comments
[-] kevincox@lemmy.ml 16 points 1 day ago

declaring multiple variables is less error-prone than in C. In C, the following declares x to be a pointer, but (surprisingly at first!) y to be a normal integer:

int* x, y;

Whereas the equivalent in Go does what you’d expect, declaring both to be pointers:

var x, y *int

I don't think this is a related at all. C could have easily decided that the definition makes both x and y pointers. They just decided not to so that you can declare more variables on one line by being able to do int x, *y, **z, .... It is more flexible.

Similarly that Go line could have been parsed like var x, (y*) int if they wanted to. They just made a different choice.

[-] mEEGal@lemmy.world 2 points 1 day ago

That's because declaring several variables on the same line is syntactic sugar, although I agree it makes little sense this way

[-] jdr@lemmy.ml 7 points 1 day ago

That's why you write

int *x, y, **z;

C doesn't write like "x is an int-pointer", rather it says "dereferencing x will get you an int".

[-] anotherandrew@lemmy.mixdown.ca 12 points 1 day ago

100% and why I think int* should be at the least a compiler warning, perhaps an outright error with pedantic enabled.

this post was submitted on 26 Jul 2026
37 points (72.8% liked)

Technology

86651 readers
4047 users here now

This is a most excellent place for technology news and articles.


Our Rules


  1. Follow the lemmy.world rules.
  2. Only tech related news or articles.
  3. Be excellent to each other!
  4. Mod approved content bots can post up to 10 articles per day.
  5. Threads asking for personal tech support may be deleted.
  6. Politics threads may be removed.
  7. No memes allowed as posts, OK to post as comments.
  8. Only approved bots from the list below, this includes using AI responses and summaries. To ask if your bot can be added please contact a mod.
  9. Check for duplicates before posting, duplicates may be removed
  10. Accounts 7 days and younger will have their posts automatically removed.

Approved Bots


founded 3 years ago
MODERATORS