Fwd: error in variable dereferencing

Andrew Haley aph@redhat.com
Thu Apr 20 15:41:00 GMT 2006


Thibaud GUERIN writes:
 > On 4/20/06, Andrew Haley <aph@gcc.gnu.org> wrote:
 > > Thibaud GUERIN writes:
 > >  > hi,
 > >  > I'm actually writing a program in C and i'm fighting with an address
 > >  > dereferencing since some days now.
 > >  >
 > >  > int            the_bug(const char *fmt, ...)
 > >  > {
 > >  >   char    **ap;
 > >  >   char        **s = (char **)(&fmt);
 > >  >
 > >  > /* __asm__ volatile ( */
 > >  > /*           "\tleal %1, %%eax\n" */
 > >  > /*           "\tmovl %%eax,%0\n" */
 > >  > /*           "\tmovl %1, %%eax\n" */
 > >  > /*           "\tmovl %2, %%ebx \n" */
 > >  > /*           "\tmovl %%eax, (%%ebx)\n" */
 > >  > /*           : "=m"(ap) : "m" (fmt), "m"(ap)); */
 > >
 > > This is wrong in so many ways I don't know where to start.
 > >
 > > It may be better if you try to tell us what you are trying to do.
 > >
 > > Redirecting gcc-help@gcc.gnu.org.
 > 
 > 
 > Not clear in the first message, (and maybe not in this one too..), sorry
 > 
 > 
 > This asm inline was something like a "test/patch code".
 > 
 > I try to have a simple :
 > 
 > char        **ap = (char **)(&fmt);

I don't think that's legal.  (Actually, I'm not perfectly sure it's
not legal, but I think not.)  Also, I have no idea why you're trying
to do such a thing.

 > working, It didn't :
 > ap was equal to &fmt BUT *ap wasn't equal to fmt (don't kown why...)

I'm sure that's impossible.  :-)

 > so i try by my self... to do :
 > 
 > ap = &fmt;
 > *ap = fmt;
 > 
 > in asm inline.... (dirty i know...)
 > 
 > problem is :
 > With this asm code in the binary *s is equal to fmt
 > Without this asm code in the binary *s isn't equal to fmt
 > 
 > 
 > All the 's' variable stuffs are from my debug...
 > Again :
 > My only aim is to have an 'ap = &fmt' valid (->ap = &fmt AND *ap = fmt)

So why not do the obvious 

  const char **ap = &fmt ;

?

 > The resulting asm was here to help you to understand wath's wrong ....
 > I'm looking for some days now without answer...

You're still not explaining yourself.  You have a const char* arg that
you are trying to alter, but instead of doing it the obvious way with
an assignment, you're taking the address of the arg, casting the
resulting pointer to a different pointer type, and then overwriting
the arg through the resulting pointer.

What's the point of all this?

Andrew.



More information about the Gcc-help mailing list