This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: What am I doint wrong here?!?!
Chris Croswhite <ccroswhite at get2chip dot com> writes:
> ummm... I tried it with the int/&int and it works for -O2, however,
> when using the other way, I have compiled this with -g and no
> problems, as soon as I use -O(1,2,3) I run into the core dump, why
> do I get a core dumb than and not with -g?
Could you post the source code that produces the core dumb?
[No need to email me. Post the the list.]
> On Sun, 2003-02-23 at 13:56, Oscar Fuentes wrote:
> > Chris Croswhite <ccroswhite at get2chip dot com> writes:
> >
> > > gcc 3.2.2 on x86 (686):
> > > What am I doing wrong here:
> > >
> > > #include <math.h>
> > > #include <stdio.h>
> > >
> > > int main () {
> > > double val, num;
> > > int *exp;
> > >
> > > val = 5.0/2.0;
> > >
> > > num = frexp(val, exp);
> > >
> > > printf("num is %g\n", val);
> > >
> > > return 1;
> > > }
> > >
> > > gcc -static -O2 foo.c -o foo
> > >
> > > foo generates a dump.
> >
> > You provided a pointer, but it points nowhere. 'frexp' uses that
> > pointer to store a value on the address it points to. Either you use
> >
> > /* We allocate a piece of memory and set 'exp' to point there */
> > int *exp = (int*) malloc( sizeof(int) );
> >
> > val = 5.0/2.0;
> >
> > num = frexp(val, exp);
> >
> > or simply
> >
> > /* Use a plain variable */
> > int exp;
> >
> > val = 5.0/2.0;
> >
> > /* We pass the address of 'exp' */
> > num = frexp(val, &exp);
> >
> > HTH
> --
> Chris Croswhite <ccroswhite at get2chip dot com>
> Get2Chip, Inc.
>
>
--
Oscar