"Shastri" <sa*****@gmail.com> writes:
I think it is compiler dependent but if you can find the size of the
variable, you can find the data type. But its not precise. Because
sometimes you may be dealing with data types which have the same size.
Not an exact procedure.
There is no library function in C.
Please provide some context. Read <http://cfaj.freeshell.org/google/>.
Knowing the size of a variable isn't useful, except in *very* narrow
circumstances, if you need to know its type. For example, something
that's 4 bytes on one system I use might be any of:
int
unsigned int
long
unsigned long
float
short[2]
unsigned short[2]
char[4]
unsigned char[4]
signed char[4]
struct { short x; char y; unsigned char z; }
among almost infinitely many other possibilities.
There is no way in C to represent a type, unless you construct your
own type descriptor type. Unlike size, a variable's type is not a
run-time attribute that you can do anything with.
If you need to know the type of a variable, you need to remember how
you declared it.
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.