Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!cica!ctrsol!uakari.primate.wisc.edu!brutus.cs.uiuc.edu!apple!oliveb!amdahl!pacbell!osc!strick From: strick@osc.COM (henry strickland) Newsgroups: comp.lang.c++ Subject: the secret bang Message-ID: <1167@osc.COM> Date: 15 Oct 89 01:24:07 GMT Reply-To: strick@osc.com (henry strickland 415-325-2300) Followup-To: comp.lang.c++ Organization: the techwood toaster pastry users group, georgia tech Lines: 82 Company: Object-Sciences Corp (God's own startup) // 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; } /////////////////////////////////////////////////////////////////////////////