h_2_bi.bas, a tool for translating .h files into .bi

User projects written in or related to FreeBASIC.
Post Reply
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: h_2_bi.bas, a tool for translating .h files into .bi

Post by MichaelW »

AGS wrote:On a 64bit version of windows an integer is 32 bits, a long is 32 bits and a long long is 64 bits.

Code: Select all

print sizeof(integer)
print sizeof(long)
print sizeof(longint)
Compiled as a 32-bit app with 0.90.1 and running on Windows7-64:

Code: Select all

 4
 4
 8
Compiled as a 64-bit app with 1.00.0 and running on Windows7-64:

Code: Select all

 8
 4
 8
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: h_2_bi.bas, a tool for translating .h files into .bi

Post by TJF »

AGS wrote:I could not find code in the h2bi package that shows how to deal with platform dependent differences (64bit).
On a 64bit version of windows an integer is 32 bits, a long is 32 bits and a long long is 64 bits.
On a 64bit version of linux an integer is 32 bits, a long is 64 bits and a long long is 64 bits as well.

Notice the difference: long is 64 bits on linux and 32 bits on windows. Meaning that translation of
long depends upon the platform used. The table h2bi uses to translate standard C types to standard
fb types does not contain platform dependent definitions.
This means that translation of long might not always turn out the way it should?
Yes, good find, thanks!

We can solve this by changing some lines in h_2_bi_Conf.bas (the user has to add #INCLUDE ONCE "crt/long.bi" manually in the section __START_BI__(){}; of the control file to make this work)

Code: Select all

  'Typ_.add(         "unsigned long ", "ULONG")
  Typ_.add(         "unsigned long ", "culong")
  'Typ_.add(           "signed long ", "LONG")
  Typ_.add(           "signed long ", "clong")
  ...
  'Typ_.add(                  "long ", "LONG")
  Typ_.add(                  "long ", "clong")
And there's an other issue regarding long double (the user has to add #INCLUDE ONCE "crt/longdouble.bi" manually in the section __START_BI__(){}; of the control file to make this work)

Code: Select all

  'Typ_.add(           "long double ", "DOUBLE")
  Typ_.add(           "long double ", "clongdouble")
I'm unsure about the long long int types. They're missing in crt/long.bi. It seems that they need a TYPE ALIAS as LONGDOUBLE. Does anybody know the correct byte size on each OS?
AGS wrote:I like the header at the German fb site
h_2_bi.bas (SWIG-Alternative, Version 0.2.4)
( Especially the SWIG-Alternative part :) ;) )
Yeah, it's from the time before fb-frog.

I tried to adapt the description. Unfortunately there's a problem with the PHP code on this site, ATM. Sebastian told me that he is working on that issue.
AGS wrote:And last but not least: how about a Geany-lua port of your tool? Using Geany-lua a program has access to the content
of a document while editing using Geany. You use Geany, other fb users use Geany... what do you think?
I don't see an advantage using lua. But why not? Start, if you like.

IMHO there's an other issue in Geany, more important: the list of type declarations / variables doesn't work correctly when multi line comments are used (and some problems with labels). This should be fixed, either by adapting the Geany code, or by a lua script, or by a plugin, written in C or FB.

[Edit]
Typos
[/Edit]
Last edited by TJF on Oct 02, 2014 7:12, edited 2 times in total.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: h_2_bi.bas, a tool for translating .h files into .bi

Post by TJF »

@MichaelW

h_2_bi translates between C and FB types, so we have to care about the byte sizes of the different types in both languages. The problem regarding the C type long is that GCC uses different sizes on the OSs. See dkls overview at Creating FB bindings for C libraries.

Unfortunately the C type long long int is missing.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

h_2_bi-0.2.8 released

Post by TJF »

I just found out that the ENUM fix also is missing in the last upload (I'm getting old - sorry guys).

So I made and uploaded a new release 0.2.8:
  • new: translated sources uses crt/long.bi declarations for C types long and crt/longdouble.bi declarations for C types long double
  • new: named enum blocks get the orig. name mangled like 'ENUM name_' and a 'TYPE AS LONG name' gets appended now
  • optimization: cosmetic changes in source
This version translates
  • long long int ==> clonglongint
  • unsigned long long int ==> culonglongint
and these FB types should either be added in crt/long.bi (prefered solution) or need individual declarations in the start section, when they occur.

Download:
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: h_2_bi.bas, a tool for translating .h files into .bi

Post by dkl »

I've adjusted the wiki page a little to mention this:

short == short int
long == long int
long long == long long int
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: h_2_bi.bas, a tool for translating .h files into .bi

Post by TJF »

So I created a new release 0.2.8.2 (for new users).

Users of 0.2.8 need not download. They can also adapt in h_2_bi_Config.bas, SUB Config.addDefTypes()

Code: Select all

' re-change culonglongint -> ULONGINT
  Typ_.add("unsigned long long int ", "ULONGINT")
  ...
' re-change clonglongint -> LONGINT
  Typ_.add(  "signed long long int ", "LONGINT")
  ...
' add new line below (order is important !!!)
  Typ_.add(         "long long int ", "LONGINT")
Post Reply