Hello I've got few questions because I'm working on some C library port to GNU GPC. On the assumption that best reasult will be maintained if 1) There will not be any unit file but only original include files with orignal tree structure {$ifndef __NAME__} {$define __NAME__} {$include <sothing.inc>} works perfectly with GPC and also -llibname -L/usr/lib/.... -I/usr/include...... too 2) all macro definitions will be converted to macro definitions NOT to wrpaer functions to avoid not neccesery function jumps in generated code 3) all inlines, functions implemented in interface of headers will be keeped as they are without any new function wrappers all this as mentioned before i did but i found one thing strange for me
Why this don't work : we've got an pointer array inside a redord field
type ppointer = ^pointer; type our_rec = packed record ptr_data : ppointer; end; var some_array : ^our_rec; needed_pointer : pointer;
imagine we got an array of pointers and
some_array^.ptr_data points at this array
when i try to acces elements in that way as it is in C ,freepascal needed_pointer := some_array^.ptr_data[2]^ {3rd element , pointer in array} i got an error something like '...trying to acces an array on somthing is not an array ...' BUT this works needed_pointer := (some_array^.ptr_data+2)^
In GPC manual http://www.gnu-pascal.de/gpc_120.html#SEC120 there is written GPC allows to increment, decrement, compare, and subtract pointers or to use them in `for' loops just like the C language. a: array [1 .. 7] of Char; p, q: ^Char; .......... for p := @A[1]
Isn't nearly the same as my example ? Maybe this is a problem of latest snapshot of gpc i use with GCC 3.2.1 ? 20021128, based on gcc-3.2.1
Second problem I got in C function like that with variable number of arguments type name (arg,arg, ....) so i implemented it as function name (arg;arg; var add_arg_) : type But i can pass only one aditional argument
Is possible to implement variable number of arguments for functions ? Or maybe i have to overload it with 2 or more similar functions ? but the way is function overloading allowed in GNU Gpc ?
3rd Question any ideas how to implement C++ library with classes inside ?
PS: GPC is going to be the best Objective Pascal compiler ....
Sincerelly Artur Bać
Artur Bac wrote:
Hello I've got few questions because I'm working on some C library port to GNU GPC. On the assumption that best reasult will be maintained if
- There will not be any unit file but only original include files with
orignal tree structure {$ifndef __NAME__} {$define __NAME__} {$include <sothing.inc>} works perfectly with GPC and also -llibname -L/usr/lib/.... -I/usr/include...... too
Yes -- though I don't think you'll need /usr/include which contains C system headers (it's not recommended to put your Pascal translations there).
- all macro definitions will be converted to macro definitions NOT to wrpaer
functions to avoid not neccesery function jumps in generated code
GPC can inline functions. This is generally just as efficient and often easier to use.
Why this don't work : we've got an pointer array inside a redord field
type ppointer = ^pointer; type our_rec = packed record ptr_data : ppointer; end; var some_array : ^our_rec; needed_pointer : pointer;
imagine we got an array of pointers and
some_array^.ptr_data points at this array
when i try to acces elements in that way as it is in C ,freepascal needed_pointer := some_array^.ptr_data[2]^ {3rd element , pointer in array} i got an error something like '...trying to acces an array on somthing is not an array ...' BUT this works needed_pointer := (some_array^.ptr_data+2)^
In GPC manual http://www.gnu-pascal.de/gpc_120.html#SEC120 there is written GPC allows to increment, decrement, compare, and subtract pointers or to use them in `for' loops just like the C language. a: array [1 .. 7] of Char; p, q: ^Char; .......... for p := @A[1]
Isn't nearly the same as my example ? Maybe this is a problem of latest snapshot of gpc i use with GCC 3.2.1 ? 20021128, based on gcc-3.2.1
I'm not sure exactly what you did (why don't you post a complete sample code), but in Pascal, pointers and arrays are not the same (FPC is like C in this regard, indeed). If you want to access it as an array, declare an array.
Second problem I got in C function like that with variable number of arguments type name (arg,arg, ....) so i implemented it as function name (arg;arg; var add_arg_) : type But i can pass only one aditional argument
GPC allows external declarations with `...'.
Is possible to implement variable number of arguments for functions ? Or maybe i have to overload it with 2 or more similar functions ? but the way is function overloading allowed in GNU Gpc ?
No (but you could declare several functions with distinct Pascal names and the same asmname).
3rd Question any ideas how to implement C++ library with classes inside ?
GPC's object model is different from C++'s. You might need wrappers written in C (compiled by g++) ...
Frank
and also -llibname -L/usr/lib/.... -I/usr/include...... too
Yes -- though I don't think you'll need /usr/include which contains C system headers (it's not recommended to put your Pascal translations there).
Yes , this could be other directory ex. /usr/pincludes or somthing else if end user will want but i think is good idea to standarize where to put them. Last days i tryed one very good tool 'buildtool' it much faster than autoconf + automake and could be easly expanded to support gnu pascal and automaticaly generate makefiles http://buildtool.sourceforge.net/ so my idea is to standarize where such tools schould search for header files.
- all macro definitions will be converted to macro definitions NOT to
wrpaer functions to avoid not neccesery function jumps in generated code
GPC can inline functions. This is generally just as efficient and often easier to use.
Yes right but more difficult to maintain when original library is changed Best is to maintain original file structure of header files with all ilines and macros as they are with minimal ingerention. Most of macro definitions are very simple and easy to recode.
Why this don't work : we've got an pointer array inside a redord field
type ppointer = ^pointer; type our_rec = packed record
..............
I'm not sure exactly what you did (why don't you post a complete sample code), but in Pascal, pointers and arrays are not the same (FPC is like C in this regard, indeed). If you want to access it as an array, declare an array.
understod, right pointer is not an array in gpc...
Second problem I got in C function like that with variable number of arguments type name (arg,arg, ....)
GPC allows external declarations with `...'.
thx i didn't find anything in manual about ,...) it is good idea to add that i think. ...................
Frank
Artur
Artur Bac wrote:
Last days i tryed one very good tool 'buildtool' it much faster than autoconf + automake and could be easly expanded to support gnu pascal and automaticaly generate makefiles http://buildtool.sourceforge.net/ so my idea is to standarize where such tools schould search for header files.
Generally, Pascal programs don't use many include files, but rather units/modules. On my machine, I put the global units in /usr/[local/]units/ ...
thx i didn't find anything in manual about ,...) it is good idea to add that i think.
Sure. Could you write some words, then I'll happily include them.
Frank