Wiki source for KeyPgAlias


Show raw source

{{fbdoc item="title" value="ALIAS (Name)"}}----
Clause of the ##[[KeyPgSub|Sub]]## and ##[[KeyPgFunction|Function]]## statements that provides an alternate internal name.

{{fbdoc item="syntax"}}##
[[[KeyPgDeclare|declare]]] { [[KeyPgSub|sub]] | [[KeyPgFunction|function]] } //usablename// **Alias "//alternatename//"** (...)
##
{{fbdoc item="usage"}}##
declare sub //usablename// Alias "//alternatename//" ( ... )
##//or//##
declare function //usablename// Alias "//alternatename//" ( ... )
##//or//##
sub //usablename// Alias "//alternatename//" ( ... )
...
end sub
##//or//##
function //usablename// Alias "//alternatename//" ( ... )
...
end function
##//or//##
type //typename// Alias "//alternatename//" ( ... )
...
end type
##
{{fbdoc item="desc"}}
##Alias## gives an alternate name to a procedure. This alternate name cannot be used within the program to call the procedure, but it is visible (if the function is not private) to the linker when linking with code written in other languages.

##Alias## is commonly used for procedures in libraries written in other languages when such procedure names are valid in the other language but invalid in BASIC. When using ##Alias## with ##[[KeyPgDeclare|Declare]]##, only the alternate name is used by the linker.

Differently from normal procedure names, ##Alias## does not change the case of the alternate name, so it is useful when external code requires an exported function with a particular name or with a particular case.

##Alias## can be used to specify an alternate name for ##[[KeyPgType|type]]## definitions.

##Alias## can be used as a modifier that specifies an alternate name mangling for procedure parameters. See ##[[KeyPgAliasModifier|Alias (Modifier)]]##

{{fbdoc item="ex"}}

If there is a sub called ##xClearScreen## in an external library and you want to reference it with the name ##""ClearVideoScreen""##, here is sample code to do so:
{{fbdoc item="filename" value="examples/manual/procs/alias.bas"}}%%(freebasic)
DECLARE SUB ClearVideoScreen ALIAS "xClearScreen" ()
%%

A procedure meant to be used by external C code, exported as ##""MyExportedProc""##:
{{fbdoc item="filename" value="examples/manual/procs/alias2.bas"}}%%(freebasic)
FUNCTION MultiplyByFive CDECL ALIAS "MyExportedProc" (BYVAL Parameter AS INTEGER) AS INTEGER EXPORT
RETURN Parameter * 5
END FUNCTION
%%

{{fbdoc item="diff"}}
- In QB, ##Alias## only worked with ##[[KeyPgDeclare|Declare]]##.

{{fbdoc item="see"}}
- ##[[KeyPgDeclare|Declare]]##
- ##[[KeyPgExport|Export]]##
- ##[[KeyPgTypeAlias|Type (Alias)]]##
- ##[[KeyPgAliasModifier|Alias (Modifier)]]##

{{fbdoc item="back" value="CatPgProcedures|Procedures"}}
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode