www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/08/01/19:45:03

Message-ID: <3B6893E6.4643339F@hotmail.nospam.com>
From: Ian Rees <ianr44 AT hotmail DOT nospam DOT com>
X-Mailer: Mozilla 4.7 [en] (Win98; I)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Type casting and pointers
References: <wyZ97.2407$n_3 DOT 3163465 AT typhoon DOT ne DOT mediaone DOT net> <9k9u34$d9c$1 AT slb7 DOT atl DOT mindspring DOT net> <pa%97.2448$n_3 DOT 3200149 AT typhoon DOT ne DOT mediaone DOT net>
Lines: 75
Date: Wed, 01 Aug 2001 19:42:30 -0400
NNTP-Posting-Host: 63.80.121.44
X-Trace: eagle.america.net 996709336 63.80.121.44 (Wed, 01 Aug 2001 19:42:16 EDT)
NNTP-Posting-Date: Wed, 01 Aug 2001 19:42:16 EDT
Organization: 24hoursupport.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019