bartop

palmoswerks ARCHIVE
Palm OS programming tips from a (former) CodeWarrior insider

header

Navigation

Search
Home
About
Stories
Stuff I Like
Articles
PilRC
CodeWarrior
palmos.techwood.org
DevTools List
Palm OS Dev FAQ

Making array access faster and safer

I've occasionally heard a complaint about using arrays with the CodeWarrior 68K compiler. Sometimes a user finds that an array access causes the compiler to emit a reference to the __lmul__ library function, which is either too far away from its use or in another segment, causing a linker error.

With modern versions of CodeWarrior for Palm OS, there's no need to put up with this. A simple code change can eliminate the call to __lmul__.

The key is making sure the index expression is a 16-bit value. To do this, use 2-byte ints and make sure that your expression only uses 16-bit values, or if needed, is cast to a UInt16/Int16.

Another way to fix this is to make sure your array is of items sized to a power of two. This can't always happen, but if it does, CW will use a shift operation to compute the array offset instead of a multiplication.

IDE Tip: Quickly jump from header to source and back

Several users have told me about their favorite IDE feature. I don't think its well publicized, so I'll talk about it here.

On Windows, Ctrl-Backtick will switch windows to the file with the same basename but different extension. The mapping treats extensions as two groups

Source files have .c, .cpp, or .cp extensions. Header files have .h or .hpp extensions. If you're in foo.cpp, and hit ctrl-backtick, you'll jump to foo.h. If you hit it again, you're back in foo.cpp.

Not all extensions will work. You can go from a PilRC source file to its header (assuming they have the same base name), but going back doesn't happen right now. Still, for most code, this is really useful.

brought to you by weblogger.com


Send feedback to combee@techwood.org
Copyright © 2004 Benjamin L. Combee
Palm OS is a registered trademark of PalmSource, Inc.
Metrowerks and CodeWarrior are registered trademarks of Metrowerks Inc.

The views expressed on this website/weblog are those of mine alone and do not necessarily reflect the views of PalmSource or Metrowerks.

This is a Manila Site

qwertYAK / frobnovich