logoalt Hacker News

phamilton • today at 2:03 PM • 3 replies • view on HN

Re: arrays are pointers.

One of my favorite things to show just how bare this is in C is to show array access commutativity.

  char c = {1,2,3}

  c[1] == *(c + 1)
  
  *(c + 1) == *(1 + c)
  
  c[1] == 1[c]
C is wonderfully simple at times.

Replies

mr_00ff00 • today at 2:28 PM

All fun and games with arrays being pointers, until you declare an array in a function and return it.

➕ show 1 reply
Ygg2 • today at 2:33 PM

Isn't Lisp even more bare bones?

At end of day minimalism is a neat but not decisive feature. If minimalism was decisive we'd all be writing Brainfuck.

➕ show 2 replies
mathisfun123 • today at 2:44 PM

> One of my favorite things to show

Who have you shown this to? What kind of person is impressed by this? Anyone that programs in any other language already knows that syntax is fungible so who cares if C chooses to use addition and brackets this way. So the only people that might be impressed by this are people who don't program. In which case why are you showing them lol.

For example (assuming you're a C programmer) are you impressed by this python syntax

  [a] * 3 == [a, a, a]
➕ show 1 reply