Revision history for DevBindingCreation


Revision [22576]

Last edited on 2019-02-26 08:30:13 by fxm [Suppressed reference to fbc version 1.04]
Additions:
{{table columns="3" cellpadding="1" cells=" C/C++ type ; Size in bytes (GCC on Linux/Windows) ; Corresponding FreeBASIC type ; 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 "}}
Deletions:
{{table columns="3" cellpadding="1" cells=" C/C++ type ; Size in bytes (GCC on Linux/Windows) ; Corresponding FreeBASIC type ; 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 (from fbc version 1.04) ; * (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 "}}


Revision [20780]

Edited on 2016-03-12 11:59:38 by fxm [Formatting]

No Differences

Revision [19973]

Edited on 2016-02-10 15:47:47 by DkLwikki [Update link format]
Additions:
- The good news: We have tools ([[http://www.freebasic.net/forum/viewtopic.php?f=8&t=18712|fbfrog]] and [[http://www.freebasic.net/forum/viewtopic.php?f=8&t=15364|h_2_bi]]) which can do most of the translation automatically.
Deletions:
- The good news: We have tools ([[http://www.freebasic.net/forum/viewtopic.php?f=8&t=18712 fbfrog]] and [[http://www.freebasic.net/forum/viewtopic.php?f=8&t=15364 h_2_bi]]) which can do most of the translation automatically.


Revision [17829]

Edited on 2015-10-04 08:18:35 by FxMwikki [Now, the Boolean type exists]
Additions:
{{table columns="3" cellpadding="1" cells=" C/C++ type ; Size in bytes (GCC on Linux/Windows) ; Corresponding FreeBASIC type ; 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 (from fbc version 1.04) ; * (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 "}}
Deletions:
{{table columns="3" cellpadding="1" cells=" C/C++ type ; Size in bytes (GCC on Linux/Windows) ; Corresponding FreeBASIC type ; 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 ; * (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 "}}


Revision [17395]

Edited on 2014-12-17 06:13:39 by DkLwikki [Add section about function types]
Additions:
{{fbdoc item="section" value="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.
%%(c)
// 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:
%%(freebasic)
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


Revision [17327]

Edited on 2014-10-11 10:00:48 by DkLwikki [Formatting]
Additions:
- Fields inside structures do not need to be renamed just because they match an FB keyword. By using the "##""As DataType Name""##" syntax they can be use FB keywords as identifiers. This only works as long as it is a simple structure (plain old data), not a class.
Deletions:
- Fields inside structures do not need to be renamed just because they match an FB keyword. By using the "##""As DataType <Name>""##" syntax they can be use FB keywords as identifiers. This only works as long as it is a simple structure (plain old data), not a class.


Revision [17326]

Edited on 2014-10-11 09:59:44 by DkLwikki [Formatting]
Additions:
- Renaming a symbol should not cause further renames (for example, if ##foo## must be renamed, but ##foo_## already exists, then ##foo## should be renamed to ##""foo__""## instead)
- Fields inside structures do not need to be renamed just because they match an FB keyword. By using the "##""As DataType <Name>""##" syntax they can be use FB keywords as identifiers. This only works as long as it is a simple structure (plain old data), not a class.
Deletions:
- Renaming a symbol should not cause further renames (for example, if ##foo## must be renamed, but ##foo_## already exists, then ##foo## should be renamed to ##foo__## instead)
- Fields inside structures do not need to be renamed just because they match an FB keyword. By using the "##As DataType <Name>##" syntax they can be use FB keywords as identifiers. This only works as long as it is a simple structure (plain old data), not a class.


Revision [17325]

Edited on 2014-10-11 09:58:33 by DkLwikki [Add extra note on field identifiers]
Additions:
- Fields inside structures do not need to be renamed just because they match an FB keyword. By using the "##As DataType <Name>##" syntax they can be use FB keywords as identifiers. This only works as long as it is a simple structure (plain old data), not a class.
Deletions:
- Fields inside structures do not need to be renamed just because they match an FB keyword. By using the ##As DataType <Name>## syntax they can be use FB keywords as identifiers. This only works as long as it is a simple structure (plain old data), not a class.


Revision [17324]

Edited on 2014-10-11 09:56:14 by DkLwikki [Add extra node on field identifiers]
Additions:
- Fields inside structures do not need to be renamed just because they match an FB keyword. By using the ##As DataType <Name>## syntax they can be use FB keywords as identifiers. This only works as long as it is a simple structure (plain old data), not a class.
%%(freebasic)
type UdtWithKeywordFields
As ZString Ptr String '' Field "String" of type ZString Ptr
As Long Type '' Field "Type" of type "Long"
As Long As '' Field "As" of type "Long"
end type%%


Revision [17323]

Edited on 2014-10-11 09:15:30 by DkLwikki [Add section on symbol name conflicts]
Additions:
{{table columns="3" cellpadding="1" cells=" C/C++ type ; Size in bytes (GCC on Linux/Windows) ; Corresponding FreeBASIC type ; 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 ; * (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 "}}
{{fbdoc item="section" value="Symbol name conflicts"}}
- ""C/C++"" is case-sensitive, with ~50 keywords
- ""FreeBASIC"" is case-insensitive, with ~400 keywords
- C code sometimes uses FB keywords as symbol identifiers, for example ##INT##, ##string##, ##open##. Such symbols must be renamed.
- C code often contains identifiers which differ only in case, for example ##GET_VERSION## and ##get_version##. This is not allowed in FB; one of the symbols must be renamed.
- In C, a macro can have the same identifier as a function. This is not allowed in FB; one of the symbols must be renamed.
{{fbdoc item="subsect" value="Examples"}}
C code using FB keywords as identifiers:
%%(c)
typedef int INT;
void open(void);
%%(freebasic)
type INT_ as long
declare sub open_ cdecl alias "open"()
C code relying on case-sensitivity:
%%(c)
void foo(void);
void Foo(void);
void FOO(void);%%
%%(freebasic)
'' Wrong translation:
extern "C"
declare sub foo()
declare sub Foo() '' error: duplicate definition
declare sub FOO() '' error: duplicate definition
end extern
%%(freebasic)
'' Correct translation:
extern "C"
declare sub foo()
declare sub Foo_ alias "Foo"()
declare sub FOO__ alias "FOO"()
end extern
Another classic example where this kind of conflict happens:
%%(c)
#define GET_VERSION_NUMBER 123
int get_version_number(void);
%%(freebasic)
extern "C"
#define GET_VERSION_NUMBER_ 123 '' renamed to avoid conflict
declare function get_version_number() as long
end extern
Conflict between procedure and macro:
%%(c)
void f(int);
#define f(i) f(i + 1)
%%(freebasic)
extern "C"
declare sub f(byval as long)
#define f_(i) f(i + 1) '' renamed to avoid conflict
end extern
{{fbdoc item="subsect" value="Solutions"}}
- Symbols should be renamed by appending ##_## underscores. This way we solve the conflicts and still stay close to the original API.
- Renaming a symbol should not cause further renames (for example, if ##foo## must be renamed, but ##foo_## already exists, then ##foo## should be renamed to ##foo__## instead)
- A list of renamed symbols should be available in the binding or in the binding's documentation such that users can identify such differences to the original API.
Deletions:
{{table columns="3" cellpadding="1" cells=" C/C++ type ; Size in bytes (GCC on Linux/Windows) ; Corresponding FreeBASIC type ; 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 ; * (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 "}}


Revision [17300]

Edited on 2014-10-03 07:56:30 by DkLwikki [Mention long int vs LongInt]
Additions:
- Caveat: ##int##/##long## is not ##Integer##/##Long##. In FB, ##Integer## corresponds to ##Pointer## - it's 32bit on 32bit and 64bit on 64bit (on all operating systems). ##Long## stays 32bit everywhere. In C, ##int## stays 32bit everywhere, and ##long## only corresponds to pointers on Linux/BSD systems, but not on ""Win64"", where ##long## is still 32bit. On ""Win64"", ##long long## is the only 64bit integer type in C. Thus, neither C's ##int## nor C's ##long## are compatible to FB's ##Integer##.
- Caveat: ##long int## is not ##""LongInt""##. FB's ##""LongInt""## corresponds to C's ##long long##, not C's ##long##.
Deletions:
Caveat: ##int##/##long## is not ##Integer##/##Long##. In FB, ##Integer## corresponds to ##Pointer## - it's 32bit on 32bit and 64bit on 64bit (on all operating systems). ##Long## stays 32bit everywhere. In C, ##int## stays 32bit everywhere, and ##long## only corresponds to pointers on Linux/BSD systems, but not on ""Win64"", where ##long## is still 32bit. On ""Win64"", ##long long## is the only 64bit integer type in C. Thus, neither C's ##int## nor C's ##long## are compatible to FB's ##Integer##.


Revision [17299]

Edited on 2014-10-02 18:53:12 by DkLwikki [Add long double to data type table]
Additions:
{{table columns="3" cellpadding="1" cells=" C/C++ type ; Size in bytes (GCC on Linux/Windows) ; Corresponding FreeBASIC type ; 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 ; * (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 "}}
Deletions:
{{table columns="3" cellpadding="1" cells=" C/C++ type ; Size in bytes (GCC on Linux/Windows) ; Corresponding FreeBASIC type ; 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 ; _Bool/bool ; 1 ; Byte ; * (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 "}}


Revision [17298]

Edited on 2014-10-02 18:41:43 by DkLwikki [Add [int] to show the optional int keyword]
Additions:
{{table columns="3" cellpadding="1" cells=" C/C++ type ; Size in bytes (GCC on Linux/Windows) ; Corresponding FreeBASIC type ; 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 ; _Bool/bool ; 1 ; Byte ; * (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 "}}
Deletions:
{{table columns="3" cellpadding="1" cells=" C/C++ type ; Size in bytes (GCC on Linux/Windows) ; Corresponding FreeBASIC type ; char ; 1 ; Byte ; short ; 2 ; Short ; int ; 4 ; Long ; enum (underlying type int) ; 4 ; Long ; long long ; 8 ; LongInt ; float ; 4 ; Single ; double ; 8 ; Double ; _Bool/bool ; 1 ; Byte ; * (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 ; 4 on 32bit systems and Win64 (!), 8 on 64bit Linux/BSD ; CLong from crt/long.bi "}}


Revision [17285]

Edited on 2014-09-22 08:37:48 by DkLwikki [Add _Bool/bool types]
Additions:
- ##BOOL## from ##windows.h## is just a typedef for ##int##, and should not be confused with the C ##_Bool## or ""C++"" ##bool## types.
Deletions:
- ##BOOL## from ##windows.h## is just a typedef for ##int##, and should not be confused with the C ##_Bool## or ''C++'' ##bool## types.


Revision [17284]

Edited on 2014-09-22 08:37:10 by DkLwikki [Add _Bool/bool types]
Additions:
{{table columns="3" cellpadding="1" cells=" C/C++ type ; Size in bytes (GCC on Linux/Windows) ; Corresponding FreeBASIC type ; char ; 1 ; Byte ; short ; 2 ; Short ; int ; 4 ; Long ; enum (underlying type int) ; 4 ; Long ; long long ; 8 ; LongInt ; float ; 4 ; Single ; double ; 8 ; Double ; _Bool/bool ; 1 ; Byte ; * (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 ; 4 on 32bit systems and Win64 (!), 8 on 64bit Linux/BSD ; CLong from crt/long.bi "}}
- ##BOOL## from ##windows.h## is just a typedef for ##int##, and should not be confused with the C ##_Bool## or ''C++'' ##bool## types.
Deletions:
{{table columns="3" cellpadding="1" cells=" C/C++ type ; Size in bytes (GCC on Linux/Windows) ; Corresponding FreeBASIC type ; char ; 1 ; Byte ; short ; 2 ; Short ; int ; 4 ; Long ; enum (underlying type int) ; 4 ; Long ; long long ; 8 ; LongInt ; float ; 4 ; Single ; double ; 8 ; Double ; * (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 ; 4 on 32bit systems and Win64 (!), 8 on 64bit Linux/BSD ; CLong from crt/long.bi "}}


Revision [17275]

Edited on 2014-09-18 19:17:54 by DkLwikki [Fix header; add small "introduction"]
Additions:
{{fbdoc item="title" value="Creating FB bindings for C libraries"}}----
This page aims to document the problems and solutions commonly encountered when creating FB bindings for C libraries.
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.
- The good news: We have tools ([[http://www.freebasic.net/forum/viewtopic.php?f=8&t=18712 fbfrog]] and [[http://www.freebasic.net/forum/viewtopic.php?f=8&t=15364 h_2_bi]]) which can do most of the translation automatically.
- The bad news: There always are some problems which cannot be solved automatically and thus need to be fixed manually.
Deletions:
{{fbdoc item="title" value="C Header Style Guide"}}----


Revision [17274]

Edited on 2014-09-18 18:36:49 by DkLwikki [Formatting]
Additions:
Caveat: ##int##/##long## is not ##Integer##/##Long##. In FB, ##Integer## corresponds to ##Pointer## - it's 32bit on 32bit and 64bit on 64bit (on all operating systems). ##Long## stays 32bit everywhere. In C, ##int## stays 32bit everywhere, and ##long## only corresponds to pointers on Linux/BSD systems, but not on ""Win64"", where ##long## is still 32bit. On ""Win64"", ##long long## is the only 64bit integer type in C. Thus, neither C's ##int## nor C's ##long## are compatible to FB's ##Integer##.
Deletions:
Caveat: ##int##/##long## is not ##Integer##/##Long##. In FB, ##Integer## corresponds to ##Pointer## - it's 32bit on 32bit and 64bit on 64bit (on all operating systems). ##Long## stays 32bit everywhere. In C, ##int## stays 32bit everywhere, and ##long## only corresponds to pointers on Linux/BSD systems, but not on Win64, where ##long## is still 32bit. On Win64, ##long long## is the only 64bit integer type in C. Thus, neither C's ##int## nor C's ##long## are compatible to FB's ##Integer##.


Revision [17273]

Edited on 2014-09-18 18:34:53 by DkLwikki [Formatting]
Additions:



Revision [17272]

The oldest known version of this page was created on 2014-09-18 18:33:36 by DkLwikki [Formatting]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode