Determining type at run-time or compile-time 
Author Message
 Determining type at run-time or compile-time

What is the best what to determine what a data type is at run-time, or at
compile-time in the preprocessor if possible?

Let me give you the context, so that you know what I am trying to do.  I am
writing a program using MPI to manipulate some data.  The data is of some
type foo_type which is defined by a typedef in a header file (suppose, for
now, that it is a primitive type).  When you send data in MPI, you have to
tell MPI what data type you are sending (this lets it translate the data if
necessary in heterogeneous networks, for example).  You do this by passing
an appropriate type constant (MPI_DOUBLE, MPI_FLOAT, MPI_INT, etcetera) to

Currently, I am doing something like:

typedef double foo_type;

I want to be able to determine this type constant automatically.  For
example, I would like to inherit the type from another header file that
knows nothing about MPI, and ensure that the correct constant is used:

#include "other_header.h"
typedef some_type foo_type;
#define FOO_TYPE_CONST_FOR_MPI ...magic here...

Is there a good way to do this?

Thanks for your suggestions.

Steven G. Johnson

PS. What I would really like is some way to compare types in the
preprocessor.  #if types_equal(foo_type,double), and so on.  But, it seems
like this isn't possible.


Sat, 27 May 2000 03:00:00 GMT  
 Determining type at run-time or compile-time



> What is the best what to determine what a data type is at run-time, or at
> compile-time in the preprocessor if possible?

A big problem you have...

We are currently trying to solve it here too, and we believe it is not
feasible using only language-specific features: C does not provide any
way to find out the type in a safe way.

Our direction of working is based on the debug information that
compilers may put in the object code. For instance, use a de{*filter*} as
gdb and you'll see it has the full type information of any data (Well,
more or less).

Some work about it was previously made here ( http://www.*-*-*.com/ ), I
think in the SOS project, which led to a tool named OCI. People at
University of Texas did a great job about it in the Texas persistent
store ( http://www.*-*-*.com/ ).

Note that the main problem is not to deal with C structs, that are
rather simple, but with the C++ classes and templates, that are rather

Anyway, this solution has two major drawbacks: it is system-dependent
and compiler dependent.

In the same way, you can also hack your compiler in order to give it
type-info features, but this will be a nightmare, believe me.

Good luck,

Fri, 02 Jun 2000 03:00:00 GMT  
 [ 2 post ] 

 Relevant Pages 

1. sizeof determined at compile time or runtime?

2. Determine Column Data Type at run time

3. Determining variable type at run-time (followup q.)

4. Determining variable type at run-time

5. sizeof operator execution - ? run time/compile time

6. determining the available storage on the stack at run time

7. Help using time.h to calculate running time...

8. Design time / run time

9. Read/Write Properties During Design Time, but Read-Only During Run-Time

10. Design-time vs Run-time mode

11. Timing problem in calling run-time loading DLL

12. Timing problem in run-time loading DLL


Powered by phpBB® Forum Software