Revision [22509]

This is an old revision of KeyPgAlias made by JeffMarshall on 2018-09-26 07:59:24.



Clause of the Sub and Function statements that provides an alternate internal name.

[declare] { sub | function } usablename Alias "alternatename" (...)

declare sub usablename Alias "alternatename" ( ... )
declare function usablename Alias "alternatename" ( ... )
sub usablename Alias "alternatename" ( ... )
end sub
function usablename Alias "alternatename" ( ... )
end function

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 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 also be used as modifier that specifies an alternate mangling for procedure parameters. For example extern c++ : declare sub proc( byval as long alias "long" ) : end extern. This form of Alias can only be used as in [unsigned] [u]long alias "long". The specific purpose is to allow FreeBASIC to call external c++ procedures (on win-64) requiring a 32-bit 'long int' type. Usage of Alias in this way affects win-64 targets only, and is ignored on all other targets.


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:
Declare Sub ClearVideoScreen Alias "xClearScreen" ()

A procedure meant to be used by external C code, exported as MyExportedProc:
Function MultiplyByFive CDecl Alias "MyExportedProc" (ByVal Parameter As Integer) As Integer Export
  Return Parameter * 5
End Function

Differences from QB:
See also:
Back to Procedures
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki phatcode