Recent

Author Topic: Universal Library Headers  (Read 22036 times)

Fred vS

  • Hero Member
  • *****
  • Posts: 1671
    • miXimum is the DJ's best friend
Re: Universal Library Headers
« Reply #15 on: March 09, 2014, 02:28:40 pm »
@ User137 :
Quote
I see that you are using both 32 and 64-bit systems. Are you ok with integer type being 32 or 64 bit too, or would you prefer to replace them with longint? Because you use cardinal, which is strictly 32-bit, i'd assume you meant longint.
Re

Yep, it is for 32/64 bit libraries. Thanks for the "cardinal" trick. I do not know that it was strictly 32 bit. I will change for longint. Thanks.

@ Taazz.

Many, many thanks for that clear explanations. And your "universal string" tip is great.

Many thanks, wonderful fpc people.
Fred.
I use Lazarus 1.8.0 32/64 and FPC 3.0.3 32/64 on Linux Mint Mate 17 32/64, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3610
  • I like bugs.
Re: Universal Library Headers
« Reply #16 on: March 09, 2014, 05:01:50 pm »
Integer is a synonym for LongInt. They are 32-bit signed. Cardinal is also 32-bit but unsigned. Int64 is always 64-bit.
PtrInt and PtrUInt size depends on the CPU architecture's pointer size.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7224
Re: Universal Library Headers
« Reply #17 on: March 09, 2014, 07:07:43 pm »
Integer is a synonym for LongInt. 

Only in $mode delphi and objfpc.  Not in TP and fpc (the default) mode.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3610
  • I like bugs.
Re: Universal Library Headers
« Reply #18 on: March 09, 2014, 07:34:13 pm »
Only in $mode delphi and objfpc.  Not in TP and fpc (the default) mode.

Ok, right, there was no mode switch in the code.

User137

  • Hero Member
  • *****
  • Posts: 1790
    • Nxpascal home
Re: Universal Library Headers
« Reply #19 on: March 10, 2014, 02:29:49 am »
Yep, it is for 32/64 bit libraries. Thanks for the "cardinal" trick. I do not know that it was strictly 32 bit. I will change for longint. Thanks.
If uncertain, this page should clarify the int types
http://www.freepascal.org/docs-html/ref/refsu5.html

smallint: -32768 .. 32767 (signed)
cardinal: 0 .. 4294967295 (unsigned)
longint: -2147483648 .. 2147483647 (signed)
integer: smallint, longint or int64 (signed)
The integer special cases were explained here: http://wiki.freepascal.org/Integer
Quote
The size of an integer is dependent upon the bit size of the target machine to which the compiler is to generate code (32 bit or 64 bit), the type of compiler (16-bit, 32-bit or 64-bit), and upon compiler switches in some cases. Typical sizes of integer generally are 16 bit, (2 byte) 32 bit (4 byte) or 64 bit (8 byte).

Fred vS

  • Hero Member
  • *****
  • Posts: 1671
    • miXimum is the DJ's best friend
Re: Universal Library Headers
« Reply #20 on: March 10, 2014, 02:14:14 pm »
Quote
Most if not all language implementations understand and can call C functions, so if you want your library to be accessible by as many languages as possible, limit the interface to what C understands.

Hum, i have added ctypes in uses section and use cint32, cfloat, ... etc.
I use Lazarus 1.8.0 32/64 and FPC 3.0.3 32/64 on Linux Mint Mate 17 32/64, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 1671
    • miXimum is the DJ's best friend
Re: Universal Library Headers
« Reply #21 on: March 10, 2014, 02:41:25 pm »
I use Lazarus 1.8.0 32/64 and FPC 3.0.3 32/64 on Linux Mint Mate 17 32/64, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Fred vS

  • Hero Member
  • *****
  • Posts: 1671
    • miXimum is the DJ's best friend
Re: Universal Library Headers
« Reply #23 on: March 10, 2014, 06:30:36 pm »
BigChimp, you are one of the most brilliant gems of fpc.
Tetra thanks.  :-*
I use Lazarus 1.8.0 32/64 and FPC 3.0.3 32/64 on Linux Mint Mate 17 32/64, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 1671
    • miXimum is the DJ's best friend
Re: Universal Library Headers
« Reply #24 on: March 23, 2014, 11:39:57 pm »
Hello.
After deeply testing a audio and a graphic fpc library, here some advice :

- For Universality, use cmem in your library.
I noted that, if foreign languages (Python, Java,  gcc,...) use fpc libraries without cmem, sometimes, i get "fragmentation fault" and it crash the application.
With cmem, it works perfectly (try with Python, Java, gcc...).

Tested on Linux 32/64 and Windows 32/64.

PS : The reverse is valuable too. I noted that fpc applications, who deals with foreign libraries, work much better using cmem.

PS2 : fpc is very impressive...  ;)
« Last Edit: March 23, 2014, 11:41:41 pm by Fred vS »
I use Lazarus 1.8.0 32/64 and FPC 3.0.3 32/64 on Linux Mint Mate 17 32/64, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs

avra

  • Hero Member
  • *****
  • Posts: 1567
    • Additional info
Re: Universal Library Headers
« Reply #25 on: March 24, 2014, 11:14:53 am »
- For Universality, use cmem in your library.
I noted that, if foreign languages (Python, Java,  gcc,...) use fpc libraries without cmem, sometimes, i get "fragmentation fault" and it crash the application.
With cmem, it works perfectly (try with Python, Java, gcc...).
Thank you for sharing this info  :)
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7224
Re: Universal Library Headers
« Reply #26 on: March 24, 2014, 05:48:06 pm »

integer: smallint, longint or int64 (signed)

Integer is never int64 on normal platforms (maybe stuff like jvm backend).

Quote
The integer special cases were explained here: http://wiki.freepascal.org/Integer

Also wrong, corrected.
 

Fred vS

  • Hero Member
  • *****
  • Posts: 1671
    • miXimum is the DJ's best friend
Re: Universal Library Headers
« Reply #27 on: March 26, 2014, 05:36:01 pm »
Hello.

After successfully used fpc libraries with Python (i will do a wiki, i promise  ;) ), i want to access those libraries from Java.

I will use => https://github.com/twall/jna  (Java Native Access).

Hum, who knows  :-[, does somebody already work with JNA and native fpc Libraries ?
Have you some example to show ?

Many thanks.

Fred
« Last Edit: March 26, 2014, 05:39:04 pm by Fred vS »
I use Lazarus 1.8.0 32/64 and FPC 3.0.3 32/64 on Linux Mint Mate 17 32/64, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs