Re: Find the Data Type of Variable




"chellappa" <N.Chellappa@xxxxxxxxx> wrote in message
news:1138722161.310948.281130@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Hi All,
> How to find the data type of the variable ?

The C language does not have a facility for doing this.

> is there any libaray
> function avaiable? Because i want create generic data type of some
> operation .

When you create an object, you know its type. E.g.:

int i;
double d;

If you keep track of this information yourself (e.g. with
a 'type flag' or such), you can implement 'generic' types
using a pointer to void (type 'void *'). Use a 'type
flag' to convey type information to a function. This is
how 'printf()' does it (e.g. "%d" in the first argument
tells it that the associated argument is type' int). Of
course things won't work if you don't actually pass the
proper type. IOW, 'void*' is quite useful, but needs
to be used with great care. A sharp, two-edged knife.


-Mike


.



Relevant Pages

  • Re: Freeing Algorithms
    ... On the other hand, int is simple, efficient, and handles very ... The data type int falls somewhere before the requirement of the user. ... To paraphrase the requirement (since requirements cannot be accurately expressed in English (or a programming language for the Mr. TDD!)), a data type that extended between negative and positive infinity is required to express the arrow of time. ... Assuming Java provided a data type that permitted an extension to infinity, then it would certainly make int look like hitherto "overkill". ...
    (comp.lang.java.programmer)
  • Re: User Input issue
    ... now we know that the int data type uses 4 bytes of memory. ... You wrote a moment ago that the programmer does not ... covered strings yet (I'm a college freshman in a Programming I/Novice ...
    (comp.lang.c)
  • RE: time_t size and year 2038 wrap
    ... > as long int. ... > redhat site for date 2038 and found very little current ... To bullet proof your code, you could declare a data type, ... or manipulations on your special versions of date-time. ...
    (RedHat)
  • Re: Working with Cash and uses of Typedef
    ... Which data type should I use instead? ... If you're tracking tenths of pennies, that same 16 bit int ... Abstraction is a powerful tool, and when done properly can make life ...
    (comp.lang.c)
  • User Input issue
    ... now we know that the int data type uses 4 bytes of memory. ... either a C-style string or C++ string and then use the stdlib header ... covered strings yet (I'm a college freshman in a Programming I/Novice ...
    (comp.lang.c)