Thread: incrementing
View Single Post
  #3   Spotlight this post!  
Unread 09-12-2006, 23:40
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: incrementing

Quote:
Originally Posted by Alan Anderson View Post
Here's something few people know about C: pointer arithmetic scales integers by the size of the type being pointed to. For example, if ptr is a pointer to an int, then ptr++ will add 2 (or whatever the native size of an int is for a particular target). If parr is a pointer to a structure of twelve bytes, parr = parr + 3 will add 36.

But don't abuse this fact. Pointer arithmetic is not necessarily something useful for programming PIC processors to control FRC robots.
That's true, however using a pointer that way for general arithmentic and casting it back to an int type would definitely be abusive and the programmer need not apply for a job in my shop.

One place I've used pointer arithmetic along those lines with the PIC is to be able to treat the PWM outputs as an array. Although there the increment in address defaults back to 1.