Contents | Index | < Browse | Browse >
2.8 Constants

  Constants and literals exist only for primitive types. Depending on the type,
  they are written in different ways.
  If the type is ambiguous, e.g. Word, Long or Float, the type will be
  determined by choosing the best fitting type within the expression. If the
  type cannot be intuitively casted, the compiler will throw a type-missmatch
  error.
  
2.8.1 Boolean Literals

  Symbol             | Description
  -------------------+----------------------------------------------------------
  True               | logical true
  False              | logical false
  On                 | same like True
  Off                | same like False
  -1 or 0            | the above values written as numbers

  Note: AmiBlitz³ does not really know booleans, a boolean is an integer
        value of either -1 (true, all bits set) or 0 (false, all bits cleared).
  
2.8.2 Integer Literals (Byte, Word, Long)

  Symbol             | Description
  -------------------+----------------------------------------------------------
  65                 | decimal for "65"
  $41                | hexadecimal for "65"
  %10001             | binary for "65"
  @"A"               | ASCII for "65", newsyntax mode required
  
2.8.3 Float Literals (Quick, Float or Double Float)
  
  Float constants can be written as integers and will be casted.
  If the fractional part is needed, they are written as decimal numbers with a
  "." (full stop) to seperate the integer from fractional part.
  
  Symbol             | Description
  -------------------+----------------------------------------------------------
  65.0               | fractal number
  0.1                | fractal number with leading 0
  .1                 | fractal number without leading 0

2.8.4 String Literals

  Strings are written in double quotes. They use 8bit for each character.
  
  Symbol             | Description
  -------------------+----------------------------------------------------------
  "A"                | string of length 1
  "Hello World!"     | string of length 12

2.8.5 Pre-defined Constants

  Symbol             | Description
  -------------------+----------------------------------------------------------
  True               | logic true,  equals to -1
  False              | logic false, equals to  0
  On                 | logic true,  equals to -1
  Off                | logic false, equals to  0
  Pi                 | 3.1415926535
                     | require optimize 4:
  #__include         | 0 if main source, -1 if included
  #__autoconstantnum | value of the next auto-increment constant (read/write)
  #__debug           | -1 if debugger is on, 0 if debugger is off
  @#constant         | -1 if the user constant "constant" was defined earlier,
                     | 0 if undefined

2.8.6 User Defined Constants

  The user can define own constants. They are always of type long and must have
  a leading "#" (hash).

  Example:
  +-----------------------------------------------------------------------------
  | 
  | #myConstant = 1234     ; define a user constant
  |
  | NPrint #myConstant + 1 ; this outputs 1235
  |
  +-----------------------------------------------------------------------------

2.8.7 Escape Sequences
  
  For use within string literals, the following escape sequences are defined:

  Symbol              | Description    
  --------------------+---------------------------------------------------------
  \\n                 | new line (ASCII #10)
  \\<hex>             | any character given by 2 digit hex value,
                      | e.g. \\40 for "@"
  \\r<nn><b>          | repeat the byte b for n times, while n is a two digit decimal number
                      |
  \\__CODELINE        | number of the current code line in sourc code
  \\__DATE__          | compile date in US format (mm/dd/yyyy)
  \\__DATE_GER__      | compile date in German format (dd.mm.yyy)
  \\__VER_MAJOR       | major verion number (from project settings)
  \\__VER_MINOR       | minor verion number (from project settings)
  \\__VER_PATCH       | patch number (from project settings)
  \\__VER_BUILD       | build number (auto-incremental)
  \\__THIS_FUNCTION   | name of the current function or "GLOBAL"
  \\__THIS_INCLUDE    | name of the current include file
  \\__THIS_POINTER    | hex pointer of the current function

2.8.8 Examples
  
  +-----------------------------------------------------------------------------
  |
  | #myConst    = 12345   
  |
  | myBool.b    = True
  | myFloat.f   = 2*Pi
  | myString.s  = "Hello World!"
  | myInt1.l    = 12345
  | myInt2.l    = $BEEF
  | myInt3.l    = %101110101011
  | myInt4.l    = @"ILBM"
  | myInt5.l    = #myConst
  |
  | version.s   = "$VER: MyProggy V\\__VER_MAJOR.\\__VER_MINOR (\\__DATE__)\\n"
  | 
  +-----------------------------------------------------------------------------


Contents | Index | < Browse | Browse >