Extern...End Extern
 
Statement block to allow calling of functions compiled for specific languages or platforms.

Syntax

Extern { "C" | "C++" | "Windows" | "Windows-MS" }
declarative statements
End Extern

Description

Extern blocks provide default calling conventions for procedures and mandate a certain name decoration.

Extern "C" blocks provide a default cdecl calling convention to procedures, and also preserve the case of all names declared within them.

Extern "C++" blocks are exactly like Extern "C" blocks but they also mangle the names declared within them in a way compatible to that of g++-4.x.

Extern "Windows" blocks provide a default stdcall calling convention to procedures, preserve the case of all names declared within them and on DOS/Windows platforms, append a "@N" suffix to procedure names, where N is the total size in bytes of any procedure parameters.

Extern "Windows-MS" blocks are exactly like Extern "Windows" blocks but do not append the "@N" suffix to procedure names in DOS/Windows platforms.

Example

Extern "C"
    '' This procedure uses the CDECL convention and is seen externally
    '' as "SomeProcedure".
    Declare Sub SomeProcedure ( ByVal As Integer )
End Extern

Extern "C++"
    '' This procedure uses the CDECL convention and its name is mangled
    '' compatible to that of g++-4.x.
    Declare Function AnotherProcedure ( ByVal As Integer ) As Integer
End Extern

Extern "Windows"
    '' This procedure uses the STDCALL convention and is seen externally
    '' as "YetAnotherProcedure@4" on DOS/Windows platforms, and
    '' "YetAnotherProcedure" on Linux platforms.
    Declare Function YetAnotherProcedure ( ByVal As Integer ) As Integer
End Extern


Dialect Differences

  • Extern blocks are only available in the -lang fb dialect.

Differences from QB

  • New to FreeBASIC

Platform Differences

  • In Linux platforms, Extern "Windows" blocks never append a "@N" suffix to procedure names.

See also