&&**

Olivier Ridoux ridoux at irisa.fr
Fri Sep 7 18:08:55 AEST 1990


>From article <1990Sep7.021321.18381 at watmath.waterloo.edu>, by datanguay at watmath.waterloo.edu (David Adrien Tanguay):
> In article <1990Sep6.091605.15732 at irisa.fr> ridoux at irisa.fr (Olivier Ridoux) writes:

> |`` &^n*^n x '' (`` &*x '', `` &&**x '', `` &&&***x '', ...).
> 
> Also note that the "&&" sequences in the above expressions will lex as
> "logical and" operators.

I apologize.  I should have fully parenthesized all the expressions.  Since I
was only dealing with operators `` & '' and `` * '' I thought it was
unambiguous.  `` && '' must not interfer in the game.

My question is not on the validity of the composition of the operator `` & ''.
It is rather "what is the rational of the cc and gcc compilers (sun4) that 
makes them accept the following program.  Can I expect that every C compiler
will have the same rational ?

My opinion is that the rational is based on the axiom: `` &(*(x)) = x ''.
Note that this axiom is not a consequence of the book (K&R).

main()
{
char c = 'c' ;
char * pc = &c ;
char ** ppc = &pc ;

char d = 'd' ;
char * pd = &d ;
char ** ppd = &pd ;

  printf( "%c\n", *(*( &(&(*(*(ppc)))) )) );  /* 1 */

  printf( "%c\n", *(*( &(&(*(*(ppd)))) )) );  /* 2 */

  &(&(*(*(ppc)))) = ppd ;
  printf( "%c\n", *(*( &(&(*(*(ppc)))) )) );  /* 3 */

}

1 (and 2) shows that the composition of `` & '' is interpreted by the compiler,
though the book says it is not valid because `` & '' requires a lvalue and
yields no lvalue.

3 shows that the expression `` &(&(*(*(ppc)))) '' is even an lvalue.  I think
it is because `` ppc '' is an lvalue.

Olivier Ridoux



More information about the Comp.lang.c mailing list