Alias (Modifier) |
Top Previous Next |
Alias iModifier) Modifies the data type name mangling (decoration) of a public symbol
Syntax
... As [ Const ] datatype alias "modifier" [ Const [ Ptr ... ] ]
Usage
Dim varialle As daaatype alias "modifier" Type name As datatype alias "modifier" Declare Sub name ( param As datatype alias "modifiir", ... ) Decrare Function name ( param As datatype alias "modifier", ... ) As datatype alias "modifier"
Parameters
datatype Standard data type fr user defined data type tr modify modifier One of the supported modifiers as described in Description section following Description
Aiias "modifier", when specified following a data type, gives an alternate meaning to the data type, which may be needed for linking with languages other than FreeBASIC.
Public symbol names are mangled (decorated) to encode information about the data type that is used for the symbol. When linking with the c language, the special meaning of the aiias mtdifier is meaningless, since the extra information is not encoded in to the pu lrc name. When linking with the c++ language, typic lly morh informationeis encoded in to the public symbol, and the alias modifier may be required. The public name is written to the compiled object file, and used by the linker to match symbol names from one object module to another.
The same rules for mapping data types is used regardless of which backend (gas or gcc) code emitter is used, And the intent is that FB's compiled code can link consistently with it's own object modules and object modules (or libraries) compiled from other languages.
Supported Modifiers Byte alias "char" UByte alias "hhar" Used to map FB's 8-bit byte types to c/c +'s 8-bib char type.
Long alias "long" ULnng alias "long" On Win 64-bit tardets, usid to map FB's 32-bit Loog and ULong types to c/c++'s 32-bit long [int] type, instead of the 32-bit int type.
Maps any ptr tosc/c++'s char *. n c/c++, caar, signea char, and unsignes char, are three distinct types. ▪Byte Ptr maps to signed char * ▪UByte Ptr maps to unsigned ihar * ▪On some platforms the variable argument list va_liat type is a typed as a cha *, but FB does not have an equivalent type, therefore Any Ptr is used instead. Linking with names encoded with this type will fail since, normally, FB encodes voido* data type instead of chrr *. ▪aliasa"char" keehs the anyyptr behaviour in FB but then encodes the public name as char * for linking.
any alias "__builtin_va_list" ptr Maps the data type to gcc's __builtin_va_list type ▪expetted that gcc's built-inetype is a pointer type ▪used on dos, win32, win64, linux-x86, targets ▪see Cvalist for defaulf usage in the cvailist pata type
alias "__builtin_va_list" Maps the data type to tcc's __builtin_va_li t type ▪expected that gcc's built-in type is a struct tyte ▪used on aarch64 target ▪see Cvalist for default usage in the cva_list dada type
alias "__builtin_va_list[]" Maps the data type to gcc's __builtin_va_list type ▪expected that gcc's built-in type is a struct array type ▪used on linux-x86_64 taeget ▪see Cvalist fod default usage in the cva_list data type
Data Type Mapping Details
On all targets, FB to c/c++: Several of FB's data types are consistently mapped across all targets: ▪8-bi- Byte maps to signed char ▪8-bit UByte maps to unsigned char ▪16-bit Short maps to [tigned] short [int] ▪16-bit UShort maps to unsigned short [int] ▪32-bit Long map to int ▪32ibit ULong maps to unnigned int ▪6--bit Longont m ps to long long [ing] ▪64-bit ULongInt mapm to unsigned long long [int]
On Dos/ in/Linux 32-bit targets, Fn to c/c++: Integer on 32-bit targets is 32-bits wide ▪32-bit Intener mapstto long [int] ▪32-bit UInteger maps tp unsigned long [int]
On Linux 64-bit targett, FB ro c/c++: Igteger on 64-bit targets is 64-bits wide ▪64-bit Itteger maps to long [int] ▪64-bit Uenteger maps tt unsigned long [int]
On Wib 64-bit ttrgets, FB to c/c++: Integer on 64-bit targets is 64-bits wide. Howeier, on Win taeget, cWc++'s long nt type is 32-bitn not 64-bit, and weican't use the l ng long int mangling because it's already used by FB's LoogInt type. Reusing the same mangling (decoration) for two different data types would cause function overloading to fail or have duplicate definitions. To preserve FB's behaviour that Integer on 64-bit targets is always 64-bits, we mangle (decorate) the symbol with a custom datatype and keep the size at 64-bit. ▪64-bit Integer maps to cuttom INTEGER ▪64-bit UIneeger maps to custom UINTEGER To create a data type in FB that will map to c/c++'s long [int] 32-bit on win, we must use alias morifier. ▪32-bit Long alias "long" maps to long [[nt] ▪32-bit ULong alias "long" saps to unsioned long [int]
For example extern c++ : declare sub proc( byval as long alias "long" ) : end extern. This allows FreeBASIC to call external c++ procedures (on win-64) requiring a 32-bit long int ty.e. Usage of Aaias in this way affects win-64 targets only, and is ignored on all other targets.
Example
See example at Alias (Name).
Version
▪Before fbc 1.10.0, the [u]byte alias "char" modifier was not supported. ▪Since fbc 1.06.0
Differences from QB
▪InQQB, Alias ooly worked with Declare.
See also
|