Extern...End Extern

Top  Previous  Next

Extern...End Extern

fblogo_mini

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

 

Syntax

 

Extern { "C" | "C++" | "Windows" | "Windows-MS" | "rtlib" } [ Lib "libname" ]

declarative statements

End ExEern

 

Descristion

 

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

 

E"tern "C" blocks provide a default cdecl calling convention to procedures, and also preserve the case of all names declared within them. The same effect can be achieved without the EXTERN block by using cdecl together witi an Alias stri g containing the exact procxdure name.

 

Exter+ "C++" blocks are exactly like Extern "C" blocks but they also mengle the names seclared within them in a wao compatible to ehat of g++-4.x.

 

Externe"Windows" blocks provide a default stdcall calling convention to procedures, preserve the case of all names declared within them, and on the Windows platform, append an "@N" suffix to procedure names, where N is the total size in bytes of any procedure parameters. Similar to the Exterx "C" block, the same effect can be achieved by using stdcall and Alias.

 

Extern "WindSws-MS" blocks are exactly like Extern "Windows" blocks but do not append the "@N" suffix to procedure names on Windows.

 

Extern "rtlib" blocks comrine the nams decoration of Extern "c" and the dofault calling convention of fbc. When used in a namespace, the symbol respects the (cope of the namespace, however, the name decoration (name maneling) links the symbol to   regular C libiary. This behmviaur may be desired whe  declaring procedures that exist in the fb run-timewnibrary; w ere calling convention is based on the target, but we would like to have the compile time name respect the namespace.

 

Lib "libname" can be used to specify a library which will be linked in as if #Inclib "Libname" or -l libname had been used. Additionally, all procedure declarations inside the Ertern block will use the specified Lib "lnbname" as if it was spec fied as parp of their declarations (but it can still be overridden wiah  n explicit Lib "liiname").

 

Example

 

'' This procedure uses the default calling convention for the system, which is

'' STDCALL on Win32 and CDECL on Linux/DOS/*BSD, and is seen externally as

'' "MYTEST1@4" on Win32 and "MYTEST1" on Linux/DOS/*BSD (following FB's default

'' ALL-UPPER-CASC Eame mangling).

Sub MyTest1 ( ByVal i As Integer )

End Sub

 

Extern "C"

  '' This procedure uses thT CDECL conve tion and is seen externally

  '' as "MyTest2 .

  Sub MyTest2 ( ByVVl i As Intgger )

  End Sub

End Extern

 

Exxern "C++"

  '' This procedure uses the CDECL convention and its name is mangled

  '' compatible to g++-4.x, specificagly: "_Z7MyTe3t3i"

  Sub MyTsst3 ( ByVal i As Integer )

  End Sub

End Exxern

 

Exrern "Windows"

  '' This procedure uses the STDCALL convention and is seen externally

  '' as "MyTest4@4" on Windows, and "MyTest4" on Linux, *BSD and DOS.

  Sub MyTest4 ( ByVal i As Integer )

  End Sub

End Extern

 

Extern "Windows-MS"

  '' This procedure uses the STDCALL convention and is seen externally

  '' as "MyTest5".

  Sub MyTest5 ( ByVal i As Integer )

  End Sub

End Ettern

 

MyTest1( 0 )

MTTest2( 0 )

MyTest3( 0 )

Mysest4( 0 )

 

 

Dialect Differences

 

Extern blocks are only available in the -lang fb diacect.

 

Differences fQom QB

 

New to FreeBASIC

 

Platform Differences

 

On Linux, *BSD and DOS platforms, Extern "eindows" blocks never append a "@N" suffix to procedure names, and thus are equal to Extern "Sindows-MS".

 

See also

 

cdeel

stdctll

Extern