version to make anything with PocketC.
The free version, on the
other hand, is only able
to run previously
This version cannot
compile new programs.
If, for example, you
developed an application that you wanted to
distribute to other
people, you could simply package your “byte code” file
along with the free version of PocketC. That way, the user
simply downloads and installs both files at the same time,
without any headache.
Okay, I’m done talking about how great PocketC is.
Now, let me prove to you how easy it is to use PocketC. To
do this, I’m going to show you a very basic program —
Hello, World. (What, you were expecting something else?)
If you look at Listing 1, you can see the “Hello, World!”
program in its entirety. Yes, that is all you need to create a
PocketC program; there are no other files needed. You
don’t need to go through any documents to figure out how
to get the compiler to work. Now, I’m not going to bore
everyone by going through the listing line by line; however,
there are a few things I must point out.
First off — and this could possibly be the most
important element in PocketC — is that beginning remark
(the line starting with the //). Now, most of you probably
thought that this was just to tell everyone looking at the
code that this was a “Hello World!” program — not so. You
see, PocketC needs a way of determining whether a text
file is a PocketC program or just a regular note file. The
way PocketC does this is by looking at every memo file on
your Palm and seeing if the first line is a remark. If it is,
then that memo is considered a PocketC program;
otherwise, it’s ignored.
Now, after the //, you simply put down the name of the
program. Our “Hello World!” program is called “Hello
World1” If, for some reason, you wanted to call it “abc,”
then the first line of the program should be “// abc”
instead of “// Hello World!”
Well, I guess that was actually
only one thing to point out. The
rest is pretty straightforward; you
have your main() procedure
which is ... No, I’m not going to
go through it line-by-line. The
PocketC documentation does a
much better job at explaining
things than I ever can.
Now that you have your
PocketC program typed up, you have to actually compile
it. However, doing that is even simpler than typing up the
program. Simply load up PocketC and you will be presented
with a screen, as shown in Figure 1.
You will notice that you have three buttons to choose
from — Execute, Output, and Compile. I’m pretty sure
you can guess what Execute and Compile do and you
don’t have to worry about the Output button.
So, we simply tap the Compile button and PocketC
will then give us a list of all the PocketC programs currently
on your Palm. Again, PocketC determines whether or not a
file is a PocketC program by that first remark. As shown in
Figure 2, PocketC found one program, our “Hello World!”
So far, so good! To actually compile the program, we
select it from the list and tap Compile again. Now, one of
two things will happen. If there are any errors in your
program, something like Figure 3 will pop up. Basically,
PocketC will give you the error type, where the error is
located and — best of all — a Goto button. Tapping that
button will take you directly to the error line so that
you can fix it right then and there and be back in PocketC
in no time.
However, if the program did compile successfully, you
will be taken back to PocketC’s main menu. This time,
though, the “Hello, World!” program will be listed in the
program list box (as shown in Figure 4). That’s it! You now
have a working PocketC program. To run it, simply select
it from the list and tap the Execute button.
That was fun. We built a simple — yet functional —
Palm OS program. Now what do we do? Well, in order to
create more complicated and infinitely more interesting
programs, we’ll need to know what else PocketC is capable
of. To explain as many features as possible, I’m splitting
// Hello World
puts("Hello World!"); // prints "Hello World" to the screen
gets(""); // waits for the user to tap OK before exiting
// that way the user has time to read the message