Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-09

h2pas and implicit types

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mattias Gaertner

I'm currently working on a h2pas gui for lazarus.
(lazarus/components/h2pas/h2paswizard.lpk).

h2pas does not translate every c 'sugar'.

1. Example

#define MPI_ARGV_NULL (char **)0

One translation could be:
const MPI_ARGV_NULL: PPChar = nil;

What is the best way to handle this? In h2pas, or with a simple 'search and replace'?

2. Example

#define MPI_ARGVS_NULL (char ***)0

This needs a new type PPPChar. One translation could be:
type PPPChar = ^PPChar;
const MPI_ARGVS_NULL: PPPChar = nil;

Will it be difficult to add this feature to h2pas? Or is there a better/easier way?

3. Example

int MPI_Group_range_incl(MPI_Group, int, int [][3], MPI_Group *);
This function defines an implicit type 'int [][3]'.
One translation is
type
  TIntArray3 = array[0..2] of integer;
  TIntPtrArray3 = ^TIntArray3;
  PMPI_Group = ^MPI_Group;
function MPI_Group_range_incl(p1: MPI_Group; p2: int; p3:
TIntPtrArray3; p4: PMPI_Group); external;

Will it be difficult to add this to h2pas?

Mattias

Reply by email

Vinzent Höfler
to Mattias Gaertner
Mattias Gaertner wrote 11 lines
I'm currently working on a h2pas gui for lazarus. (lazarus/components/h2pas/h2paswizard.lpk). h2pas does not translate every c 'sugar'. 1. Example #define MPI_ARGV_NULL (char **)0 One translation could be: const MPI_ARGV_NULL: PPChar = nil;
const
    MPI_ARGV_NULL = NIL;
What is the best way to handle this?

Usually I'd suggest shooting the programmer who writes such idiocy, but I guess that's not an option here. :->

Show quoted text 5 lines
2. Example #define MPI_ARGVS_NULL (char ***)0 This needs a new type PPPChar.

No. This is (usually pre-ISO-C) nonsense to create a "typed" NULL pointer.

Solution is the same as above. C's NULL pointer is compatible to all pointer types, just like NIL in Pascal, so there's no need to define such stupid macros.

It's probably based on the same stupid idea to write stuff like "(char*)malloc(...)" instead of including the correct header files.

Vinzent.

Reply by email

Marc Santhoff
to Mattias Gaertner: I'm currently working on a h2pas gui for lazarus.…
Mattias Gaertner wrote
I'm currently working on a h2pas gui for lazarus. (lazarus/components/h2pas/h2paswizard.lpk). h2pas does not translate every c 'sugar'.

4. Example: Function pointers getting "void" type

H5MM_allocate_t = void;
function H5Pset_vlen_mem_manager(plist_id:hid_t;
  alloc_func:H5MM_allocate_t; alloc_info:pointer;
             ^^^^^^^^^^^^^^^
  free_func:H5MM_free_t; free_info:pointer):herr_t;cdecl;external;

How should the mapping to pascal be? Would NIL be sufficient because it's some typed pointer?

Marc

Reply by email