Mail Archives: djgpp/2001/08/01/19:45:03
try looking for pointers, or pointer variables.
Steve Dondley wrote:
> Marp,
>
> Great, thanks so much. One othe question, though. The book doesn't cover
> the "float *" and "float **" casts. The book just weirdly throws it into
> this example with no explanation. Must be an editor's mistake. Where can I
> learn about this? I've tried looking this up on various web C tutorials but
> haven't been able to find it.
>
> "Marp" <marp AT 0 DOT 0 DOT 0 DOT 0> wrote in message
> news:9k9u34$d9c$1 AT slb7 DOT atl DOT mindspring DOT net...
> > The only purpose of typecasting in the example given is to suppress a
> > compiler warning. It's not a good example :-) Normally you would use
> > typecasting to override the compiler's default behavior in promoting data
> > types.
> >
> > Given this:
> >
> > int a = 1;
> > double b = 2.5;
> > double c;
> >
> > And this:
> >
> > c = a + b;
> >
> > The variable c will hold 3.5 because the compiler promotes a to double for
> > the purposes of the addition.
> >
> > But this:
> >
> > c = a + (int)b;
> >
> > The variable c will hold 3 since you told it to demote b to int (which
> > causes it to use the truncated value of b for addition).
> >
> > BTW, you get a warning in the book's example without a cast because you
> are
> > assigning a float ** to a float *. They are not the same thing.
> >
> > Hope this helps.
> >
> > - Marp
> >
> > "Steve Dondley" <stevedondley AT mediaone DOT net> wrote in message
> > news:wyZ97.2407$n_3 DOT 3163465 AT typhoon DOT ne DOT mediaone DOT net...
> > > Hello,
> > >
> > > I've got a newbie C question. I've got a beginner's C book that doesn't
> > > explain something very well. Example code from the book:
> > >
> > > float *p;
> > > float balance[10][5];
> > > ...assignment stuff here...
> > > p = (float *) balance;
> > >
> > > My code works just fine without the (float *) type cast, but I do get a
> > > warning. Why exactly do you need it? Doesn't declaring *p as a float
> > > pointer at the top of the source take care of that? The book also never
> > > explains what exactly the asterisk in (float *) is. I'm just assuming
> it
> > > type casts the pointer.
> > >
> > > Can someone please provide some elucidation? Thanks!
> > >
> > > ---Steve
> > >
> > >
> > >
> >
> >
- Raw text -