Implicit Declarations

Lazy declaration of variables.

The qb and fblite FreeBASIC language dialects allow variable names to be used without declaring them first. This is called implicit or lazy declaration since the actual declaration is inferred from how the name is first used.

Variable Type
When a variable is implicitly declared, its type depends on one of two things: the most recent default implicit type directive, if any, or the variable type suffix symbol used, if any.

Default type
In the qb dialect, implicitly declared variables default to Single type, while in the fblite dialect they default to Integer type.

Default implicit type directives
"DEFxxx" directives dictate the new default type for any following implicit variable declarations. These directives are: DefByte, DefUByte, DefShort, DefUShort, DefInt, DefUInt, DefLng, DefSng, DefDbl and DefStr.

Variable type suffix symbols
Variable names suffixed with one of a certain set of symbols will be implicitly declared of a certain type. These symbols are: '%' for Integer, '&' for Long, '!' for Single, '#' for Double and '$' for String. These symbols override previous "DEFxxx" directives, if any.

Implicit Array Declaration
Currently, FreeBASIC does not support implicit declaration of arrays.

For full debugging support, all variables must be explicitly declared and suffixes should not be used. The use of Option Explicit is recommended to turn of support for implicit declarations, so that mistyped variable names are caught at compile time by the compiler.

See also:
Back to Programmer's Guide
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki phatcode