delorie.com/archives/browse.cgi | search |
From: | "Steve Dondley" <stevedondley AT mediaone DOT net> |
Newsgroups: | comp.os.msdos.djgpp |
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> |
Subject: | Re: Type casting and pointers |
Lines: | 73 |
X-Priority: | 3 |
X-MSMail-Priority: | Normal |
X-Newsreader: | Microsoft Outlook Express 5.50.4133.2400 |
X-MimeOLE: | Produced By Microsoft MimeOLE V5.50.4133.2400 |
Message-ID: | <pa%97.2448$n_3.3200149@typhoon.ne.mediaone.net> |
Date: | Wed, 01 Aug 2001 22:13:41 GMT |
NNTP-Posting-Host: | 66.31.252.175 |
X-Complaints-To: | abuse AT mediaone DOT net |
X-Trace: | typhoon.ne.mediaone.net 996704021 66.31.252.175 (Wed, 01 Aug 2001 18:13:41 EDT) |
NNTP-Posting-Date: | Wed, 01 Aug 2001 18:13:41 EDT |
Organization: | Road Runner |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Reply-To: | djgpp AT delorie DOT com |
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 > > > > > > > >
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |