FreeBASIC マニュアルのトップに戻る

FreeBASIC DevBindingCreation

目次→FreeBASIC のハッキング→FreeBASIC でのハッキングのための情報Creating FB bindings for C libraries←オリジナル・サイト

C ライブラリのために FB 装丁をつくる



このページは、Cライブラリのための FB バインディングを作成する時に、一般的に遭遇する問題と解決策の文書です。

In general, FB and C/C++ are very similar. FB follows the same ABI as GCC where applicable, in order to be binary-compatible as much as possible. The language syntax is also similar to C/C++. As a result, a lot of type and procedure declarations can be translated directly 1:1 between C and FB. However, there also are constructs which cannot be translated directly, for example: typedefs declaring function types. FB has function pointer types, but not plain function types.


Data types

C/C++ type Size in bytes (GCC on Linux/Windows) Corresponding FreeBASIC type (on 32bit or 64bit)
char 1 Byte
short [int] 2 Short
int 4 Long
enum (underlying type int) 4 Long
long long [int] 8 LongInt
float 4 Single
double 8 Double
long double 12 on 32bit, 16 on 64bit CLongDouble from crt/longdouble.bi
_Bool/bool 1 Byte / Boolean
* (pointer) 4 on 32bit, 8 on 64bit Ptr/Pointer
ssize_t, intptr_t 4 on 32bit, 8 on 64bit Integer
size_t, uintptr_t 4 on 32bit, 8 on 64bit UInteger
long [int] 4 on 32bit systems and Win64 (!), 8 on 64bit Linux/BSD CLong from crt/long.bi


Symbol name conflicts


Function types

In C it's possible to have typedefs with function types. Dereferencing a function pointer type results in a function type. FB only has function pointer types, but not function types.

// A function typedef (function result = void, no parameters)
typedef void F(void);

// Using it to declare a function called f1
F f1;

// Usually f1 would be declared like this (use of function typedefs is pretty rare):
void f1(void);

// A more common use for function typedefs is to declare pointers to them (function pointers):
extern F *pf1;


Since FB does not have function types, such typedefs have to be solved out, or turned into a function pointer:

Extern "C"

Type F As Sub()  '' Function pointer type

'' Declaring procedures is only possible with Declare in FB
Declare Sub f1()

'' But at least FB has function pointer types.
'' Since F already is the function pointer in the FB translation, there is no extra PTR here
Extern pf1 As F

End Extern

FreeBASIC の開発者用情報 に戻る
目次に戻る
ページ歴史:2021-12-28 06:55:41
日本語翻訳:WATANABE Makoto、原文著作者:DkLwikki

ホームページのトップに戻る

表示-非営利-継承