Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
OrbWorks Community Forum • View topic - PocketC Language (v3): Macro Helper

PocketC Language (v3): Macro Helper

Postby cao on Sat Mar 24, 2001 1:06 am

<b>Macro definition</b>

__VERSION__ : 3.0.0 /* indicate the compiler version */
__PKTC__ : 1 /* indicate it is PocketC compiler */
__PKTC_CE__ : 1 /* indicate it is PocketC CE compiler */

__FILE__ : current file path
__LINE__ : current line
__DATE__ : compiled date
__TIME__ : compiled time

<b>Macro Directive</b>

<u>#ifdef</u>

#ifdef command (like #if and #ifndef) can be used to conditionally include lines of text, this can be any other type of line or command except #elseif or #endif.

Note that this command only checks on a single variable .

A common use of this command is as a method of creating block comments. Simply specify a variable you know does not exist!

Syntax
#ifdef VariableName

The "VariableName" specifies a variable that should exist for the test to evaluate to true.

Example #1
#define Fruit 1
#ifdef Fruit
...
#endif

Example #2 - Block Comment
#ifdef DoesNotExist
This paragraph
has been commented out
as we are testing for
a variable we
know does not exist.
#endif

<u>#ifndef</u>
#ifndef command (like #ifdef) can be used to conditionally include lines of text, this can be any other type of line or command except #else or #endif.

Note that this command only checks on a single variable.
Syntax
#ifndef VariableName

The "VariableName" specifies a variable that should NOT exist for the test to evaluate to true.

Example
#define Fruit 1
#ifndef Fruit
...
#endif

<u>#endif</u>

This command is used to terminate a previous #ifdef or #ifndef command. There should be a matching #endif for every #ifdef or #ifndef command.


<u>#else</u>

This command is used if you wish to have some lines included when the #ifdef or #ifndef condition is false.

#define Fruit 1
#ifdef Fruit
...
#else

#endif


<u>#define</u>

#define NAME ?¢‚Ǩ‚Äú defines a simple macro. The name of the macro must begin with a letter and can consist of any combination of letters and numbers. Case is significant. This form is limiting, in that the variable names are fixed. More flexibility can be obtained by using a macro with arguments, described below.

#define NAME(a, b, c,) ?¢‚Ǩ‚Äú defines a macro with arguments. This can be used in more complex situations. The name of the macro must begin with a letter and can consist of any combination of letters and numbers. In fact, the implementation defines the arguments as simple macros. The names may be any choice of letters. Remember that case is significant in macro names.

<u>#include</u>
Using the include keyword, it becomes possible to write programs whose source code is longer than 32K or create files of frequently used code. The contents of the included file are functionally inserted into the line containing the include keyword.
For Windows CE OS, #include must contain the full path name. CE OS doesn't support relative path.


Example
<pre id=code><font face=courier size=2 id=code>

// MyFunctions.pc File
times5(int x) { return x*5;}

Another memo:
// My Program
#include "MyFunctions"
main() {
int y;
y = times5(7);
putsl(y); // Prints 35
}
The compiler sees this as:
// My Program
times5(int x) { return x*5;}
main() {
int y;
y = times5(7);
putsl(y); // Prints 35
}
</font id=code></pre id=code>


To see these Macro helper in action, check out this example.

<pre id=code><font face=courier size=2 id=code>

/*******************************************************************************
Test out macro preprocessor

A simple macro is a kind of abbreviation. It is a name which stands for a fragment of code. Some people refer to these as manifest constants.

Before you can use a macro, you must define it explicitly with the `#define' command. `#define' is followed by the name of the macro and then the code it should be an abbreviation for.

For example,
*******************************************************************************/

#define BUFFER_SIZE 1020

/*******************************************************************************
defines a macro named `BUFFER_SIZE' as an abbreviation for the text `1020'. Therefore, if somewhere after this `#define' command there comes a Pocket C statement of the form
*******************************************************************************/

int Buffer[BUFFER_SIZE];

/*******************************************************************************
After the preprocessor expands a macro name, the macro's definition body is appended to the front of the remaining input, and the check for macro calls continues. Therefore, the macro body can contain calls to other macros. For example.
*******************************************************************************/

#define BUFSIZE 1020
#define TABLESIZE BUFSIZE

/*******************************************************************************
the name `TABLESIZE' when used in the program would go through two stages of expansion, resulting ultimately in `1020'.

To define a macro that uses arguments, you write a `#define' command with a list of argument names in parentheses after the name of the macro. The argument names may be any valid C identifiers, separated by commas and optionally whitespace. The open-parenthesis must follow the macro name immediately, with no space in between.

*******************************************************************************/


#define assert(x,msg) { if ((x)==0) putsl("assert: " + msg + " File: " + __FILE__ + "(" + __LINE__ + ")" ); }

#define APPLE "apple"
#define ORANGE "orange"

/******************************************************************************
There are also predefined macros
*******************************************************************************/
main()
{
putsl("BUFFER_SIZE = " + BUFFER_SIZE);
putsl("BUFSIZE = " + BUFSIZE);
putsl("TABLESIZE = " + TABLESIZE);
putsl("__VERSION__ =" + __VERSION__);
putsl("__PKTC__ =" + __PKTC__);
putsl("__PKTC_CE__ =" + __PKTC_CE__);
putsl("__FILE__ =" + __FILE__);
putsl("__LINE__ =" + __LINE__);
putsl("__TIME__ =" + __TIME__);

assert((APPLE == ORANGE),"apple is not an orange!");

}


</font id=code></pre id=code>




Edited by - cao on 03/23/2001 19:10:54
cao
 
Posts: 60
Joined: Tue Dec 05, 2000 4:11 am
Location: USA

Return to PocketC for CE KB

Who is online

Users browsing this forum: No registered users and 1 guest

cron