This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Fwd: error in variable dereferencing
On 4/21/06, Andrew Haley <aph@gcc.gnu.org> wrote:
> Thibaud GUERIN writes:
> > On 4/20/06, Andrew Haley <aph@redhat.com> wrote:
> > > Thibaud GUERIN writes:
> > > >
> > > >
> > > > 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.
> >
> > as i'm compiling with :
> > -Wall -Werror -nostdinc -Wstrict-aliasing=2
> > it will not compile if it wasn't (i think, not sure too...)
>
> That is not true. We don't gurantee to generate an error for all
> invalid source.
>
> > > > 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. :-)
> >
> > it wasn't belive me... and it's driving me crasy since days....
> >
> > > > 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 ;
> > >
> > > ?
> >
> > because i need to do some :
> > ap++;
> > to get the next args in stack, as my end aim is to do re-write a printf...
>
> So why not use va_list? That's what va_list is for.
>
> > > > 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?
> >
> > i'm not trying to alter an (const char*) but to get the args in my
> > stack by getting some pointers on it, as in all va_args fonctions....
>
> Trying to do all this stuff behind the compiler's back is likely to
> break things. Use va_list.
>
> Andrew.
>
quote :
I'm compiling with (to run on my VM):
-std=gnu99 -Wall -Werror -nostdinc -Wstrict-aliasing=2 -fno-builtin
-I../include -I../
no-builtin ....
I'm doing that because the va_list wasn't working too... (i come to
that dirty code by simplifing the code to found the root of the
problem)
And my final aim is to have a printf without any deps form any parent
system (no use of standard includes, ....)
--
Thibaud