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

 Permanent link to archive for 9/18/01.   Tuesday, September 18, 2001 daytail

What's the deal with "static"?

Oops... I'm taking a breather from the last topic to address a question I see about once a month. Someone asks why all these functions in the Palm OS sample code have static on their definitions.

First, what does static mean? In C and C++, when static is used on a function, it limits the functions visibility within your program to the file where it is compiled. Functions without this keyword can be called from any file, and they might be called accidentally if they have a common name.

In CodeWarrior, the compiler has a very useful switch called "Require Function Prototypes". When this is on, the compiler will complain if you call a function that has no prototype. It will also complain if you define a function where no prototype already existed for it. This is designed so you won't accidentally pollute the global namespace. You can defeat this mechanism by using the static keyword. Since the function you define with that isn't visible outside the current file, it doesn't accidentally infringe on the namespace of other files and the compiler doesn't need to complain.

Since most early Palm OS work was done with CodeWarrior, the example code tends to follow this convention. I think its a good one -- with this, you don't accidentally have link problems, since everything either is contained in your one source file or its declared in a common header file.

Next time -- back to big data!

brought to you by weblogger.com

 
September 2001
Sun Mon Tue Wed Thu Fri Sat
  1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30  
Aug   Oct


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