3 ms·
The caret is because ↑ (arrow up, in case HN drops it) wasn't really "typeable" (or even available) in most computers. I'm not sure if Wirth's Pascal even had t
by badsectoracula 5y ago
The caret is because ↑ (arrow up, in case HN drops it) wasn't really "typeable" (or even available) in most computers. I'm not sure if Wirth's Pascal even had the caret - i do have an old book about Pascal which uses the arrow for pointers, but i remember seeing the caret in various dialects.
IMO Pascal actually has much better pointer syntax than C, even with the caret (which is basically a pointer/arrow up without the tail):
1. Pointer de-referencing is done via something that looks like a pointer and doesn't reuse some math operator (despite writing C for more than two decades i still pause for a bit whenever i want to multiply a pointer to a number)
2. Getting the address of something is via the "at" character @ (which kinda makes sense as a pointer to something is a way to refer "at" it), no way to mix the two
3. No special syntax for referencing a member of a record (struct) through a pointer, all record members are referenced using a dot ".", all pointers are de-referenced through the caret "^" so of course all members to a record pointer is done through using both of them: "^."
Also i think that the reason C has -> is because in C pointer de-reference is a prefix whereas in Pascal is a suffix so without it you'd either have to write (*ptr).foo. Pascal avoids that by having both be suffix operators.
- layer8 5y agoASCII actually had up-arrow instead of caret before 1967/1968, although that was slightly before the birth of Pascal (published in 1970).
- jecel 5y agoYes, the preliminary (1963) ASCII had an up arrow instead of the caret and a left arrow instead of the underline. DEC, Xerox and others built equipment around the 1963 draft and failed to change when the final version of ASCII came out. That is why when Pascal and Smalltalk came along later they used the "wrong" characters. In the case of Smalltalk, it was Digitalk's "Methods" (the precursor of Smalltalk/V) that adopted := for assignment in place of the left arrow (though the IBM PC character set actually had one, just not with the same code as ASCII 1963) since all of its tutorials were aimed at Pascal programmers.
- jacquesm 5y agoHey there Jecel, how are you doing? Any progress on your super interesting projects?
- RicardoLuis0 5y ago> Also i think that the reason C has -> is because in C pointer de-reference is a prefix whereas in Pascal is a suffix so without it you'd either have to write (*ptr).foo. Pascal avoids that by having both be suffix operators. That distinction comes from early C (pre-ANSI / K & R C), where structures were really definitions of offsets (and said offsets were global, you couldn't have different 'offsets' for a member with the same name in different structs). Say you had a struct 'struct mystruct {int a;int b;int c};': You could do '200.b' to access the value at the 'b' offset of the memory location '200' ( '*(int*)( 200 + offsetof(struct mystruct,b) )' or '((struct mystruct*)200)->b' ) And '200->b' would access offset 'b' of the memory pointed to by memory location '200' ( '*(int*)( *(intptr_t*)200 + offsetof(struct mystruct,b) )' or '(*(struct mystruct**)200)->b' )