4

I'm trying to translate the important parts of OpenMPI's mpi.h to the D programming language so I can call it from D. (HTOD didn't work at all.) I can't wrap my head around the following bits of code:

typedef struct ompi_communicator_t *MPI_Comm;
OMPI_DECLSPEC extern struct ompi_communicator_t ompi_mpi_comm_world;
OMPI_DECLSPEC extern struct ompi_communicator_t ompi_mpi_comm_self;
OMPI_DECLSPEC extern struct ompi_communicator_t ompi_mpi_comm_null;

The problem is that ompi_communicator_t is never defined in mpi.h and mpi.h doesn't include any other file besides stddef.h, which clearly doesn't contain a definition. (The comment says it's included for ptrdiff_t.) These are the only four lines in mpi.h that contain the string ompi_communicator_t. Where is the definition of this struct coming from? Are there any tricks I should be aware of where types can appear out of thin air? (There are several other structs like this, but this is the first one I stumbled upon.)

dsimcha
  • 67,514
  • 53
  • 213
  • 334

1 Answers1

3

This is a pointer to the struct, which internals are not visible outside the OpenMPI. Use any type which can hold a pointer, e.g. (in C) void*.

osgx
  • 90,338
  • 53
  • 357
  • 513
  • Thanks. I never realized that such undeclared-but-used structs are legal in C (they aren't in D). I just made a completely bogus struct to shut the D compiler up about it not being defined since, as you and CyberShadow mention, it's really all just memory addresses anyhow. – dsimcha Aug 04 '11 at 18:09
  • 1
    I've always used empty structs in these cases: `struct test{}` – jpf Aug 05 '11 at 07:35
  • 1
    @jpf: That's exactly what I ended up doing. – dsimcha Aug 05 '11 at 21:14