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

Bruno Félix Rezende Ribeiro oitofelix at ...181...
Sat Apr 26 05:57:00 CEST 2014


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].

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?

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'.

-- 
 ,= ,-_-. =.  Bruno Félix Rezende Ribeiro (oitofelix) [0x28D618AF]
((_/)o o(\_)) There is no system but GNU;
 `-'(. .)`-'  GNU Linux-Libre is one of its official kernels;
     \_/      All software must be free as in freedom;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20140426/779d5979/attachment.sig>


More information about the User mailing list