News for hackers. Stuff that matters.
Re:Zig cc: A drop-in replacement for GCC/Clang by agapon on Tuesday March 24, 2020 @06:12PM (#22679635)
I mean, is this C-like?

  fn add(a: i32, b: i32) i32 {
      return a + b;
  }
Re:Zig cc: A drop-in replacement for GCC/Clang by AndyKelley on Tuesday March 24, 2020 @06:17PM (#22679690)
Re:Zig cc: A drop-in replacement for GCC/Clang by iruoy on Tuesday March 24, 2020 @07:06PM (#22680021)
Simple stuff like this looks very similar to Rust: https://godbolt.org/z/spkKai

Rust quickly becomes harder though, while Zig is much easier to grasp.

Re:Zig cc: A drop-in replacement for GCC/Clang by tsimionescu on Tuesday March 24, 2020 @07:21PM (#22680129)
The fact that they compile to the same assembly instruction does not make them similar source code.
Re:Zig cc: A drop-in replacement for GCC/Clang by abainbridge on Wednesday March 25, 2020 @09:18AM (#22684216)
The languages are similar enough that the Zig tool-chain can translate C source into Zig source. There's mostly a one-to-one correspondence.
Re:Zig cc: A drop-in replacement for GCC/Clang by balfirevic on Tuesday March 24, 2020 @07:19PM (#22680113)
It could hardly be more C-like. Are you getting distracted by the syntax?
Re:Zig cc: A drop-in replacement for GCC/Clang by kelnos on Tuesday March 24, 2020 @07:30PM (#22680181)
When we talk about something being "C-like", the syntax is what we're talking about. Being "distracted by the syntax" doesn't make sense when the syntax is the entire point of the statement being made.
Re:Zig cc: A drop-in replacement for GCC/Clang by dnautics on Tuesday March 24, 2020 @08:14PM (#22680519)
Admittedly it's been decades since I've done any C (literally since 1999, except for an LD_PRELOAD shim I wrote about 5 years ago) but being someone who prefers C and other ALGOL-syntax derivates I find the syntax to be relatively easy to grok. One advantage over C is that the confusing pointer/array/function pointer thing has a well-defined order in Zig, there's no "spiral order" nonsense going on.
Re:Zig cc: A drop-in replacement for GCC/Clang by naniwaduni on Tuesday March 24, 2020 @08:32PM (#22680688)
There is no spiral. C's pointer declaration syntax is arguably backwards ("declaration follows usage") but fundamentally follows normal precedence rules. The so-called spiral is total nonsense misinformation.
Re:Zig cc: A drop-in replacement for GCC/Clang by dnautics on Tuesday March 24, 2020 @10:02PM (#22681322)
That's exactly my point. It's confusing enough that someone e made a bullshit claim that was totally wrong and confused noobs for years. That won't happen with zig.
Re:Zig cc: A drop-in replacement for GCC/Clang by pjmlp on Wednesday March 25, 2020 @02:59AM (#22682543)
That won't happen with any sane systems language all the way back to Algol dialects.

The only thing that C has taken from Algol, was structured control and data.

Re:Zig cc: A drop-in replacement for GCC/Clang by saagarjha on Tuesday March 24, 2020 @09:57PM (#22681288)
What about this do you find disagreeable? http://c-faq.com/decl/spiral.anderson.html
Re:Zig cc: A drop-in replacement for GCC/Clang by palotasb on Wednesday March 25, 2020 @04:16AM (#22682832)
The spiral rule works if "pointer to" and "function returning"/"array of" alternate but it breaks if they don't, i.e., if you have arrays of arrays or pointers to pointers.

    int** arr1_of_arr2_of_arr3_of_ptr_to_ptr_to_int[1][2][3]
In this case, spiraling between [1], ×, [2], ×, [3], int is obviously wrong, the correct reading order is [1], [2], [3], ×, ×, int. (Edit: read × = *)

The Right-Left Rule is quoted less frequently on HN but it's a correct algorithm for deciphering C types: http://cseweb.ucsd.edu/~ricko/rt_lt.rule.html

Re:Zig cc: A drop-in replacement for GCC/Clang by diegoperini on Wednesday March 25, 2020 @07:40AM (#22683650)
I would name that algorithm "inside-out" instead of "right-left" if my understanding of its behavior is correct.
Re:Zig cc: A drop-in replacement for GCC/Clang by saagarjha on Wednesday March 25, 2020 @01:33PM (#22686698)
Aren't you supposed to treat multiple array or pointers as a group?
Re:Zig cc: A drop-in replacement for GCC/Clang by dnautics on Tuesday March 24, 2020 @10:02PM (#22681327)
The fact that it's wrong if you try to generalize it beyond the examples given?
Re:Zig cc: A drop-in replacement for GCC/Clang by saagarjha on Tuesday March 24, 2020 @11:53PM (#22681807)
Does it? Here's one that I grabbed from cdecl.org:

  char * const (*(* const bar)[5])(int )
And its translation:

  declare bar as const pointer to array 5 of pointer to function (int) returning const pointer to char
This seems like what I'd get from the spiral technique.
Re:Zig cc: A drop-in replacement for GCC/Clang by ant6n on Wednesday March 25, 2020 @03:09AM (#22682575)
They are both close-to-the-metal, few-abstractions, procedural, imperative Systems programming languages with explicit memory management and layout.
Re:Zig cc: A drop-in replacement for GCC/Clang by balfirevic on Tuesday March 24, 2020 @07:38PM (#22680240)
When "we" talk? I suggest that in the future if you mean syntactically similar you say syntactically similar.

But then, of course, it wouldn't have much to do with Zig's "appeal as better C than C", which prompted this whole discussion.

Re:Zig cc: A drop-in replacement for GCC/Clang by agapon on Wednesday March 25, 2020 @07:36PM (#22689457)
Exactly. I would appreciate an explanation what makes zig c-like if its syntax is nothing like c? What does "c-like" even mean then?
Re:Zig cc: A drop-in replacement for GCC/Clang by yarrel on Tuesday March 24, 2020 @09:52PM (#22681263)
It's about 50% C-like. Which is giving people a That Dress experience answering yes or no to the question.