Author Topic: h2pas and C99's complex numbers  (Read 1646 times)


  • Newbie
  • Posts: 1
h2pas and C99's complex numbers
« on: November 26, 2018, 03:01:59 pm »

I am looking into accessing a C library from pascal that uses C99's 'double complex' variable type. When using h2pas on the header file containing such complex number variable types, I get a syntax error.

I am guessing that this isn't supported by h2pas?

Is there an official way to safely map C99's complex numbers to their pascal counterparts in UCOMPLEX?

Thanks in advance for any help!


  • Hero Member
  • *****
  • Posts: 3635
Re: h2pas and C99's complex numbers
« Reply #1 on: November 28, 2018, 11:53:29 pm »
I think someone made a lib for complex numbers....

You could do that yourself you know , you need a record with the Real and imaginary fields and a few basic
functions to do the math...

 from the help file..
[next] [prev] [prev-tail] [tail] [up]

15.4  Arithmetic operators

Arithmetic operators define the action of a binary operator. Possible operations are:


To multiply two types, the
multiplication operator must be overloaded.


To divide two types, the
division operator must be overloaded.


To add two types, the
addition operator must be overloaded.


To subtract two types, the
subtraction operator must be overloaded.


To exponentiate two types, the
exponentiation operator must be overloaded.

Unary minus

is used to take the negative of the argument following it.

Symmetric Difference

To take the symmetric difference of 2 structures, the
operator must be overloaded.

The definition of an arithmetic operator takes two parameters, except for unary minus, which needs only 1 parameter. The first parameter must be of the type that occurs at the left of the operator, the second parameter must be of the type that is at the right of the arithmetic operator. The result type must match the type that results after the arithmetic operation.

To compile an expression as


  R : real; 

  C,Z : complex; 





One needs a definition of the multiplication operator as:

Operator * (r : real; z1 : complex) z : complex; 


begin := * r; := * r; 


As can be seen, the first operator is a real, and the second is a complex. The result type is

include the unit "ucomplex" but I don't know if it supports all of what you need, you may need to add on..

« Last Edit: November 28, 2018, 11:58:50 pm by jamie »
The only true wisdom is knowing you know nothing


  • Full Member
  • ***
  • Posts: 215
  • Whasup!?
Re: h2pas and C99's complex numbers
« Reply #2 on: November 29, 2018, 03:49:59 pm »
[…] Is there an official way to safely map C99's complex numbers […]
In C99's § 6.2.5 (13) (page 46) its says:
Each complex type has the same representation and alignment requirements as an array type containing exactly two elements of the corresponding real type; the first element is equal to the real part, and the second element to the imaginary part, of the complex number.
So, ucomplex.pp defines complex as a record of two reals back-to-back. real is either a single or double, depending on the platform. So you can either map single complex or double complex, but not both. Now, I'm no specialist about aligning, but that's potentially an issue, too.
Yours Sincerely
Kai Burghardt


TinyPortal © 2005-2018