Live data from Hacker News

Clockwise/Spiral Rule (1994)

c-faq.com

51–59 of 59 posts

Re: Clockwise/Spiral Rule (1994)

#51
Learning this rule will mean you miss out on the opportunity to use one of the best words in the English language, which is “boustrophedonically” (meaning alternating left to right with right to left “as an ox ploughs a field”[1]).

C is parsed boustrophedonically.

[1] This is apparently the ancient Greek origin of the word.

Re: Clockwise/Spiral Rule (1994)

#53
post #3

> "str is an array 10 of pointers to char" Wow, imagine if it was possible to actually use a language like that do declare the type of the variable like that? Something like str: array [0..9] of ^Char; or even var str [10]*uint8 Just imagine...

Or even

  var str: array[10, ptr char]

Re: Clockwise/Spiral Rule (1994)

#54
post #53
post #3

> "str is an array 10 of pointers to char" Wow, imagine if it was possible to actually use a language like that do declare the type of the variable like that? Something like str: array [0..9] of ^Char; or even var str [10]*uint8 Just imagine...

Or even var str: array[10, ptr char]

Eh, or that, I guess. I personally would rather not squish the type of the elements together with the dimensions, but it can work like that, sure. Especially if you use square brackets for generic instantiation, so your example is semantically close to std::array of C++. But if the language uses the square brackets (almost) exclusively for array indexing, then having simply "[10]" prefix as a shorthand for "array of 10 of ..." à la Zig/Go is quite reasonable. Then again, Go does use square brackets both for instantiation of generics and for array-related operations so... I guess they had the syntax of map types as a precedent.

Re: Clockwise/Spiral Rule (1994)

#55

I've written some C code recently, and it came to me perhaps the pointer syntax may not be ideal. I'm not sure what the ideal would be, but I think a different notation for usage and declaration could make it less confusion. In particular I associate '*' (used as *ptr, i.e. content that ptr points to), with content, as opposed to '&' (from &var, address of var), so again '*' means content thing points to. But in decl…

I thought it was a bit of a miss that C didn't use ^ as the pointer sigil. I mean it's literally pointing. I'm guessing some early terminals didn't have that character on the keyboard.

[deleted]

Re: Clockwise/Spiral Rule (1994)

#56
post #41
post #34

Earlier quoted context omitted.

No, I think he means that for any given type, you can wrap it in an array the same way. Your example is demobstating that it even works recursively, but it works in the simple case too by wrapping "int" in an array to get an array of ints. There's no need to jump back and forth between each side when adding new layers (which gets described as a "spiral", but in a single line of code, I'd argue that it's really just j…

If I would add another array, it would look like: int c_style_array[2][5][3]; There is also no jumping back and forth. C declarations are also recursively constructed. One can complain about the irregularity of pointers syntax.

Yes, if you only use arrays, then it doesn't make things confusing. The point they were making (as I understand it) is that putting a pointer inside std::array doesn't change the way you have to read it, which is not the case for C arrays.

Re: Clockwise/Spiral Rule (1994)

#57
post #31

Earlier quoted context omitted.

The "existing type" in your example is int, the "extra layer" is the array type that "wraps" it

I guess? That's pretty confusing wording, and a bizarre rant if so.

I don't find it confusing or bizarre, but those are both subjective, so I can't say that you're wrong.

Re: Clockwise/Spiral Rule (1994)

#58
post #53

Earlier quoted context omitted.

Or even var str: array[10, ptr char]

Eh, or that, I guess. I personally would rather not squish the type of the elements together with the dimensions, but it can work like that, sure. Especially if you use square brackets for generic instantiation, so your example is semantically close to std::array of C++. But if the language uses the square brackets (almost) exclusively for array indexing, then having simply "[10]" prefix as a shorthand for "array of…

> Especially if you use square brackets for generic instantiation, so your example is semantically close to std::array of C++.

Yes, it is like that.

Re: Clockwise/Spiral Rule (1994)

#59

Earlier quoted context omitted.

i find Zig does it fairly well. there is also no ambiguity between pointer and multiply.

Yeah, they took it from Pascal: var p: ^integer, i: integer; p := @i; p^ := 42; Which follows an obvious "if modifier of a base type goes to the left of the type, then the operator that uses this modifier goes to the right in the expression". Just like "array of T/[]T" translates into "arr[index]".

well pascal doesnt use ^ for multiplication
Post reply on HN