Fwd: error in variable dereferencing

Andrew Haley aph@gcc.gnu.org
Fri Apr 21 15:26:00 GMT 2006


Thibaud GUERIN writes:
 > >
 > > Now, if you know absolutely for sure that your args are pushed onto
 > > the stack in order without any holes, you might be able to get around
 > > this.
 > >
 > > void pkludge (char *s, ...) __attribute__((noinline));
 > > void pkludge (char *s, ...)
 > > {
 > >   void **p = &s;
 > >   printf ("%d\n", *(int *)++p);
 > >   printf ("%d\n", *(int *)++p);
 > > }
 > >
 > > This isn't legal C, though, and trying to do things like this behind
 > > gcc's back is asking for trouble.  The _real_ solution is to find out
 > > why gcc's builtins are not working.
 > >
 > 
 > Thanks for all the tips (maybe REALLY usefull later).
 > 
 > But my problem right now is that :
 > 
 > int			my_own_printf(char *fmt, ...)
 > {
 >   char		**s = (char **)(&fmt);
 > 
 >  if (*s == fmt)
 >    write(1, "they are the same\n", 18);
 >  else
 >    write(1, "they aren't the same\n", 21);
 >   return (0);
 > }
 > 
 > prints "they aren't the same" ....

OK, so we've got rid of the asms and casting away const, and the code
still doesn't work.

So, your code is now, at last, legal C.  Let's have a look at the
assembly code generated for my_own_printf (use gcc -S).  Be sure to
include the exact command line you used.

Andrew.




More information about the Gcc-help mailing list