Let's swap data!
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 24-01-2007, 17:41
brianafischer brianafischer is offline
Registered User
FRC #0503 (Frog Force)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2003
Location: Michigan
Posts: 17
brianafischer is on a distinguished road
Typecasting Resources

It seems that many students are bitten by the typecasting bug. I cannot seem to find a definitive reference on typecasting for FIRST and would like to generate some more documentation on this topic. Are there any specific "sections" or white papers that cover this topic? If not, I will consider writing one...

Please post your examples and resources that you would like me to include.

-Brian
  #2   Spotlight this post!  
Unread 24-01-2007, 19:05
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,082
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: Typecasting Resources

The MPLAB C18 Compiler User's Guide goes over the peculiarities of the PIC18's type conversion system, which actually goes against the ISO C mandates regarding automatic type conversions.
  #3   Spotlight this post!  
Unread 24-01-2007, 19:55
TimCraig TimCraig is offline
Registered User
AKA: Tim Craig
no team
 
Join Date: Aug 2004
Rookie Year: 2003
Location: San Jose, CA
Posts: 221
TimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to behold
Re: Typecasting Resources

I suspect the underlying problem is that the students don't understand the size implications of the different variable types and what happens when you invoke arithmetic operations where the result exceeds that size. Or just how easy it is to exceed the size. Simply adding two quantities can produce an overflow. Also, with integer arithmetic the order the operations are specified can how a profound impact on the result. Understanding these topics is required to understand why most of the casting that is needed to program the FIRST RC is necessary.
  #4   Spotlight this post!  
Unread 24-01-2007, 22:58
brianafischer brianafischer is offline
Registered User
FRC #0503 (Frog Force)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2003
Location: Michigan
Posts: 17
brianafischer is on a distinguished road
Re: Typecasting Resources

Quote:
Originally Posted by TimCraig View Post
I suspect the underlying problem is that the students don't understand the size implications of the different variable types and what happens when you invoke arithmetic operations where the result exceeds that size. Or just how easy it is to exceed the size. Simply adding two quantities can produce an overflow. Also, with integer arithmetic the order the operations are specified can how a profound impact on the result. Understanding these topics is required to understand why most of the casting that is needed to program the FIRST RC is necessary.
That sums it up pretty well. I plan on creating a resource to spread the understanding of this issue. It is mentioned sporadically, but never really explained in the FIRST documents that I have browsed...

Please post more info/examples on this topic if you can!
  #5   Spotlight this post!  
Unread 25-01-2007, 02:17
TimCraig TimCraig is offline
Registered User
AKA: Tim Craig
no team
 
Join Date: Aug 2004
Rookie Year: 2003
Location: San Jose, CA
Posts: 221
TimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to behold
Re: Typecasting Resources

Quote:
Originally Posted by brianafischer View Post
Please post more info/examples on this topic if you can!
The simplest example I can think of is:

char x = 65;
char y = 66;

char a;
int b;

/* a is not large enough to hold 131 even if the arithmetic did what was expected. a equals -125. */
a = x + y;

/* b = large enough to hold 131 but the arithmetic will still be done as above since the compiler doesn't look at the left side of the equation. */
b = x + y;

/* Force the arithmetic to be done in 16 bits by casting one of the members */

/* a still can't hold 131 but the compiler should issue a warning for loss of precision if the warning level isn't high enough. ALWAYS set the warning level as high as possible! */
a = (int) x + y;

/* This gets rid of the warning but is still wrong. */
a = (char) ((int) x + y);

/* The "correct" way to do it. b = 131 */
b = (int) x + y;
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Resources Peg Cwiakala General Forum 1 31-03-2006 07:21
Rookie Resources... Gurdian General Forum 5 13-03-2006 07:53
Team Resources alfman05302001 General Forum 4 04-05-2004 15:51
List of Resources? Eric Bareiss General Forum 9 31-01-2004 07:51
Resources archiver 2000 1 23-06-2002 23:49


All times are GMT -5. The time now is 03:49.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi