&&**

Wayne Throop throopw at sheol.UUCP
Mon Sep 10 06:54:55 AEST 1990


> From: ridoux at irisa.fr (Olivier Ridoux)
> "what is the rational of the cc and gcc compilers (sun4) that 
> makes them accept the following program.

Presumably, merely because they are buggy compilers.

> Can I expect that every C compiler will have the same rational ?

I certainly hope not.  It seems to me that about the only way that
allowing &(&(...)) makes any sense at all is as part of a larger
picture that supports the operation of essentially all "lvalue"
requiring operators on value arguments.  This larger context would
have to deal with rules for things like when, how, and for how long
"pseudo-objects" would be created so that lvalue-requiring semantics
could be meaningful.  It might improve the language in some ways.

I emphasize: "might".

Now, on the other hand, I ran this program through microsoft C,
feeling confident that it would be flagged as erronious.  To my
surprise and amazement, it ran just as Olivier describes.  No
slips, no drips, (and worst) no errors.

This is apparently a VERY common bug.  It shakes my faith in
the competence of C implementors.  Unless I'm missing something
quite major...???


(the program in question:)

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 */

}
--
Wayne Throop <backbone>!mcnc!rti!sheol!throopw or sheol!throopw at rti.rti.org



More information about the Comp.lang.c mailing list