Run-time type information 
Author Message
 Run-time type information

Hi there.
Is there any way to get the type information of a variable during
run-time, without having to devise a new typing mechanism or
modifying the C's compilation system ?
For example, given this declaration :

typedef struct test {
   int i;
   char *c;
   double f;

Quote:
} Test;

Test *testptr;

then I must be able to determine the type of the 'testptr' pointer
during run-time. Are there any C functions, or global variables, or
whatever, that can be used ?
Thanks...

Lukito



Fri, 25 Apr 1997 10:41:24 GMT  
 Run-time type information

Quote:
> Is there any way to get the type information of a variable during
> run-time, without having to devise a new typing mechanism or
> modifying the C's compilation system ?

    Well, it depends a bit on what you mean by typing mechanism, but
    the easiest way to do this is probably to add tag identifiers to
    the structure, eg...

        #define TYPETEST    1

        typedef struct TEST {
            int     type;
            int     i;
            char    *c;
            double  f;
        } TEST;

    Then given a function that takes a pointer and needs to determine
    its type, you can do something like...

        void    Lukito(p) /*========================================*/
        void    *p;
        {
            switch (*(int *)p) {
                case (TYPETEST):
                    {
                    TEST    *pT;
                        pT = (TEST *)p;
                        ...
                    }
                    break;

                ...
            }
        }

    Depending on what you want to do with these structures, you may
    find it useful to also add a structure length field after the type
    field, etc.

Quote:
> Lukito

--

***             Count Templar, ELITE, Cobra Mk III (FM-287)             ***


Fri, 25 Apr 1997 17:47:49 GMT  
 Run-time type information


Quote:
>Hi there.
>Is there any way to get the type information of a variable during
>run-time, without having to devise a new typing mechanism or
>modifying the C's compilation system ?
>For example, given this declaration :

>typedef struct test {
>   int i;
>   char *c;
>   double f;
>} Test;

>Test *testptr;

>then I must be able to determine the type of the 'testptr' pointer
>during run-time. Are there any C functions, or global variables, or
>whatever, that can be used ?
>Thanks...

I don't understand why you want to do this - why not determine the
type at compile time? Of course, you could use C++, but that's a different
newsgroup.
--

   Flames should be redirected to /dev/null - I don't know what
   I'm saying myself so don't expect it to make sense all the time!         */



Mon, 05 May 1997 03:54:23 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Bug in C# run-time type information?

2. Enabling Run-Time Type Information: how?

3. Run-Time Type Information (RTTI) among dlls

4. Templates and MFC run-time type information

5. Enable Run-Time Type Information

6. RunTime Type Information

7. C++ runtime type information

8. how to set Run-Time Type Information (RTTI) in .Net?

9. Does embedded VC++ 3.0 support runtime type information i.e. the /GR compiler switch?

10. Determining type at run-time or compile-time

11. No type information at compile time ?

12. Catching run-time debug information

 

 
Powered by phpBB® Forum Software