Symbols

mikroBasic PRO for ARM symbols allow you to create simple macros without parameters. You can replace any line of code with a single identifier alias. Symbols, when properly used, can increase code legibility and reusability.

Symbols need to be declared at the very beginning of the module, right after the module name and (optional) include clauses. Check Program Organization for more details. Scope of a symbol is always limited to the file in which it has been declared.

Symbol is declared as:

symbol alias = code

Here, alias must be a valid identifier which you will use throughout the code. This identifier has a file scope. The code can be any line of code (literals, assignments, function calls, etc).

Using a symbol in the program consumes no RAM – the compiler will simply replace each instance of a symbol with the appropriate line of code from the declaration.

Here is an example:

symbol MAXALLOWED = 216          ' Symbol as alias for numeric value
symbol PORT = GPIO_PORTC         ' Symbol as alias for SFR
symbol MYDELAY = Delay_ms(1000)  ' Symbol as alias for procedure call

dim cnt as byte  ' Some variable

'...
main:

if cnt > MAXALLOWED then
  cnt = 0
  PORT.1 = 0
  MYDELAY
end if

Note: Symbols do not support macro expansion in a way the C preprocessor does.

Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code