Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternatives to C++ Reference/Pointer Syntax

What languages other than C and C++ have explicit reference and pointer type qualifiers? People seem to be easily confused by the right-to-left reading order of types, where char*& is "a reference to a pointer to a character", or a "character-pointer reference"; do any languages with explicit references make use of a left-to-right reading order, such as &*char/ref ptr char? I'm working on a little language project, and legibility is one of my key concerns.

It seems to me that this is one of those questions to which it's easy for a person but hard for a search engine to provide an answer. Thanks in advance!

like image 989
Jon Purdy Avatar asked Jan 19 '26 10:01

Jon Purdy


2 Answers

Stroustrup is on record as saying the declaration syntax is "an experiment that failed". Unfortunately, C++ has to go along with it for C compatibility. The original idea was that a declaration looked like a use, for example:

char * p;  // declare
* p;       // use (dereference)

but this quickly falls apart for more complex declarations. Many people (at least many Pascal programmers) prefer the syntax:

variable : type;

where type is something like:

array of char

which is about as readable as you are going to get, and is left-to-right.

I think this is defunct but it might be of use to you: http://en.wikipedia.org/wiki/Significantly_Prettier_and_Easier_C%2B%2B_Syntax

like image 34
jmucchiello Avatar answered Jan 22 '26 01:01

jmucchiello