[Gambas-user] Feature request: absolute C data type equivalents and native type aliasing

Benoît Minisini gambas at ...1...
Sat Apr 26 13:06:27 CEST 2014


Le 26/04/2014 05:57, Bruno Félix Rezende Ribeiro a écrit :
> Hello Gambas users and developers!
>
> I'm working on a module for Gambas, fully written in Gambas language,
> which aims to provide full access to the X Window System's Xlib library
> through a high-level Gambas-ish interface.  I'm in the very beginning,
> but I've been making progress and so far I've implemented 9% of the
> features of the C language X interface as described in [1].

I don't want to discourage you, but I think XLib will not be used 
anymore in a few years because of Wayland. :-/

>
> However, I'm facing a major problem that needs to be addressed before
> I get too far.  Let's take a look at a particular instance of it.
> Various Xlib functions accept or return a C 'long' data-type
> parameter.  GCC reports that on my x86 machine 'long' is 4 bytes wide
> while on my x86_64 machine it's 8 bytes wide instead.  AFAIK, Gambas
> 'Integer' and 'Long' data-type are always 4 and 8 bytes wide,
> respectively, regardless of architecture.  How can I cope with that
> when declaring external functions and structures?

This is one of many design errors of XLib.

Use the "Pointer" datatype each time you see a long. It has the same 
behaviour.

>
> The only solution I could think of is to use Gambas' preprocessor
> directives, but it isn't practical to put a preprocessor
> conditional again and again every time I'm declaring something
> which uses the same C language type:  I'd have to do that several
> hundreds of times!  So, I'd suggest to provide absolute C data type
> equivalents to 'char', 'short', 'int', 'long', 'long long', 'float',
> 'double' and 'long double', so we could interface smoothly with C
> libraries and write robust and easy to maintain components for Gambas,
> entirely in Gambas language.  In this case the C compiler would decide
> what's the wideness of each data type at Gambas' compilation time.
> One suggestion for their names is: "CChar", "CShort", "CInt", "CLong",
> "CLongLong", "CFloat", "CDouble" and "CLongDouble".
>
> This feature alone would be a great improvement, but not enough.  Within
> C libraries it's a common practice to define conditionally new data
> types in terms of the native ones.  In order to have a complete
> environment to interface with external libraries inside Gambas, we also
> need a way to make aliases to native Gambas' data types conditionally.
> It could well be a preprocessor facility, but that isn't required at
> all.  I'd suggest something that looks like:
>
> #If ARCH = "x86"
> #  AliasType("CLong", "XID")
> #Else
> #  AliasType("CInt", "XID")
> #Endif
> #AliasType("XID", "WindowID")
> #AliasType("XID", "FontID")
>
>
> Thanks in advance.
>
>
> Footnotes:
>
> [1] http://www.x.org/releases/X11R7.7/doc/libX11/libX11/libX11.html
> [2] Like 'Window', 'Font', 'Pixmap', 'Colormap', 'Cursor' and
>      'GContext'.
>

I can't add any native datatype to Gambas at the moment. You must wait 
for something like Gambas 4. :-)

Regards,

-- 
Benoît Minisini




More information about the User mailing list