strick@osc.COM (henry strickland) (10/15/89)
// Here's one for your C++ puzzle book.
//
// Without looking below, try specifying the type signature "reference
// to pointer to integer" (int* &) using the empty "[]" operator
// instead of the "*" operator. Then try getting it right.
// Now try specifying it with the secret "!" operator.
//
//
//
// The correct signature with the "[]" operator is function r1() below.
//
//
//
// Curious to AT&T cfront2.0 is the undocumented postfix-bang operator.
// It can only be used in type declarations, to mean the same thing as
// the prefix-star operator or the postfix-empty-brackets operator.
// The secret bang is demonstrated in v4(), v5(), and r4().
//
// However I can't get r5() to work, so maybe it's not exactly the same,
// or maybe the precedence of the operators in the grammer won't allow it,
// or maybe I'm trying the wrong stuff. Can anyone fix r5(),
// or figure out why you can't?
//
// Any conjectures why the secret bang is there? Wasn't postfix "!" a
// dereference operator in BCPL? Know of any other C or C++
// implementations that accept it?
//
// strick
//
// strick@osc.com
// (recently strick@gatech.edu)
//
// P.S. Let's no one argue about its merit as a feature of C++. It's
// not, and will never be, and should never be. It's just curious!
// =======================================================================
// Pass an (int*) by value: These all specify equivalent signatures.
int v0 ( int * ) ;
int v1 ( int [] ) ;
int v2 ( int *x ) ;
int v3 ( int x[] ) ;
int v4 ( int ! ) ; // using the secret bang
int v5 ( int x! ) ;
// Pass an (int*) by reference: These all specify equivalent signatures.
int r0 ( int* &) ;
int r1 ( int (&)[] ) ; // correct version of f5() and f8()
int r2 ( int* &x ) ;
int r3 ( int (&x)[] ) ; // correct version of f7() and f9()
int r4 ( int (&) !) ; // using the secret bang
//int r5 ( int (&x) !) ; ?? I can't get this to work ??
// These were my first guesses for the syntax of r1(), r3(), r4(), and r5().
// The following are all incorrect.
//int r11 ( int [] &) ; // error: syntax error
//int r33 ( int &x[] ) ; // error: array of references
//int r44 ( int ! & ) ; // error: syntax error
//int r55 ( int x! & ) ; // error: syntax error
//int r111 ( int &[] ) ; // error: array of references
//int r333 ( int &x[] ) ; // error: array of references
//int r444 ( int & !) ; // error: array of references
//int r555 ( int &x ! ) ; // error: array of references
// check to make sure the above do what I think. These are all accepted.
int v2 ( int* x ) { return *x; }
int v3 ( int* x ) { return *x; }
int v4 ( int* x ) { return *x; }
int v5 ( int* x ) { return *x; }
int r2 ( int* &x ) { return *x; }
int r3 ( int* &x ) { return *x; }
int r4 ( int* &x ) { return *x; }
int r5 ( int* &x ) { return *x; }
/////////////////////////////////////////////////////////////////////////////bs@alice.UUCP (Bjarne Stroustrup) (10/17/89)
osc.com (henry strickland 415-325-2300) of the techwood toaster
pastry users group, georgia tech, Object-Sciences Corp (God's own startup)
writes:
// Curious to AT&T cfront2.0 is the undocumented postfix-bang operator.
// It can only be used in type declarations, to mean the same thing as
// the prefix-star operator or the postfix-empty-brackets operator.
Yuck. I thought we finally had gotten it out!
// Any conjectures why the secret bang is there? Wasn't postfix "!" a
// dereference operator in BCPL?
Infix ! is the BCPL subscripting operator. What you saw was a supposedly
removed fragment of an experiment to provide a representation for C and
C++ that could be written using the ISO 646 character set standard without
the use of national characters as operators.
FYI, ASCII is the US national version of ISO646 (assuming I got the number
right) and it has the curious feature that the 6 character codes designated
for alphabetic characters have been used as operators. Most European
languages have more letters in the alphabet than English and use those
character codes for those ``extra'' letters. In particular, if
I wants to write in my native language (Danish) I cannot also use the
symbols []{}\| when using a device with a ISO646 character set.
Someone from the Danish ISO committee and the Danish Unix Users' Group
me to find a representation that allowd them to write C++ in Danish and
other European languages. We havene't had much luck with the proposal
(you can find it in one of the EUUG newsletters from this year), but
! was the subscript operator, the replacement for [].
// P.S. Let's no one argue about its merit as a feature of C++. It's
// not, and will never be, and should never be. It's just curious!
Agreed.mike@thor.acc.stolaf.edu (Mike Haertel) (10/17/89)
In article <1167@osc.COM> strick@osc.com (henry strickland 415-325-2300) writes: >// Here's one for your C++ puzzle book. > [ . . . ] >// Curious to AT&T cfront2.0 is the undocumented postfix-bang operator. >// It can only be used in type declarations, to mean the same thing as >// the prefix-star operator or the postfix-empty-brackets operator. >// The secret bang is demonstrated in v4(), v5(), and r4(). > [ . . . ] >// Any conjectures why the secret bang is there? Wasn't postfix "!" a >// dereference operator in BCPL? Know of any other C or C++ >// implementations that accept it? Obviously, the use of a postfix "pointer" declarator obviates the need for the (sometimes very tricky) parenthesization of complex declarations. Consider the (C) declaration: void (*signal(int, void (*)(int)))(int); If we take ! as a postfix declarator that means the same as * we get: void signal(int, void !(int))!(int); which can literally be read from left to right. Ravi Sethi wrote a really neat paper about this. -- Mike Haertel <mike@stolaf.edu> ``There's nothing remarkable about it. All one has to do is hit the right keys at the right time and the instrument plays itself.'' -- J. S. Bach