You Are Here:

Community: Developer Discussion Boards

#1 Old Source-code preprocessor - 2003-05-16, 19:19

Join Date: Mar 2003
Posts: 21
doomer999
Offline
Registered User
Hi,

In the documentation "Efficient MIDP programming", it is mentioned that using "source-code preprocessor" is better than "static final" variables. What exactly is it? How to use it?

Thank you
Nelson
Reply With Quote

#2 Old 2003-05-19, 16:13

Join Date: Mar 2003
Posts: 86
Location: Austria
mcmcdonald
Offline
Regular Contributor
I am interesting too in using a preprocessor integrated in wtk,...

McMc
Reply With Quote

#3 Old 2003-08-19, 03:32

Join Date: Mar 2003
Posts: 162
Location: Malaysia-Johor-Pontian Kecil
akokchai
Offline
Regular Contributor
Hi,

What I guess is like that:

If our MIDP suite has 2 files A and B. Inside A, we define 5 "static final" constant, inside B, we define 4 "static final". The 6 "static final" must "eat" some spaces in the .jar.

How abt we create another class C? This class is ONLY used to define constants and we can move the 9 variables to C. After compiled, constants in A and B will be all replaced by the actual values from C. And then, we can remove C since C is useless in the suite. This way can save the spaces for defining constants in the A and B.

I hope I don't mistake the meaning.. :)

Good lucks.
Reply With Quote

#4 Old 2003-08-19, 10:02

Join Date: Mar 2003
Posts: 86
Location: Austria
mcmcdonald
Offline
Regular Contributor
Hi!

Good idea !

Thanks
McMc
Reply With Quote

#5 Old 2003-08-19, 23:42

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
That's right... static final members are expensive on space. A pre-processor is used by C compilers to process the source code before the compiler sees it. You will see directives in C programs like:

#define MAX_ARRAY_SIZE 256

which defines a constant. The compiler itself never sees this... this directive tells the pre-processor to replace every occurance of the text "MAX_ARRAY_SIZE" within the source code with the text "256". So the source code reads:

char ach [MAX_ARRAY_SIZE];

but the compiler sees:

char ach [256];

(The pre-processor has enough of an understanding of C not to replace text in double-quotes, for example).

So in a C program, there is no difference between a symbolic-constant (one with a name) and a literal-constant (one that just has a value).

C and Java are sufficiently similar that you can get away with using a C pre-processor with a Java program. You'd need to add an appropriate command to your 'make' routine. Using the pre-processor from the GNU C compiler, that would be something like:

cpp -P -nostdinc -undef MyClass.java

You can also make use of other feature of the pre-processor, like conditional compilation, which allows you to include extra sections of code for a "debug build", or exclude them from a "production build".

Graham.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia