473,385 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Find the Data Type of Variable

Hi All,
How to find the data type of the variable ? is there any libaray
function avaiable? Because i want create generic data type of some
operation .
Thanks All
By
Chellappa

Jan 31 '06 #1
5 16881


chellappa wrote On 01/31/06 10:42,:
Hi All,
How to find the data type of the variable ?
Remember it.
is there any libaray
function avaiable?
No.
Because i want create generic data type of some
operation .


If it's truly "generic" you don't need to know
the type. To the extent that type knowledge is needed,
you're not writing generic code.

--
Er*********@sun.com

Jan 31 '06 #2

"chellappa" <N.*********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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
Jan 31 '06 #3
On Tue, 31 Jan 2006 07:42:41 -0800, chellappa wrote:
Hi All,
How to find the data type of the variable ? is there any libaray function
avaiable? Because i want create generic data type of some operation .

Inclose your data in a struct and parse the struct. The struct then needs
a variable holdind the type:

enum mytype {TYPE1, TYPE2, ...}

struct generic_type {
enum mytype thetype;
void* data;
}

--
Hilsen/Regards
Michael Rasmussen
http://keyserver.veridis.com:11371/p...rch=0xE3E80917

Feb 1 '06 #4
Hi,

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.
Cheers
Shastri

Feb 1 '06 #5
"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.
Feb 1 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
3
by: Daniel Graifer | last post by:
Why doesn't c++ support virtual data? It supports class data of type pointer to function (that's what virtual functions really are). In terms of implementation, why can't I have other types of...
10
by: Zap | last post by:
Widespread opinion is that public data members are evil, because if you have to change the way the data is stored in your class you have to break the code accessing it, etc. After reading this...
4
by: Lucas Sain | last post by:
Hi, I think thta for this I have to use reflection... but I'm not shure. How can I find/get an object at runtime by looking for its name that is stored in a variable. For example: I have a...
7
by: Arpan | last post by:
The .NET Framework 2.0 documentation states that An Object variable always holds a pointer to the data, never the data itself. Now w.r.t. the following ASP.NET code snippet, can someone please...
5
by: SunnyDrake | last post by:
HI! I wrting some program part of it is XML config parser which contains some commands(for flexibility of engenie). how do i more simple(if it possible not via System.Reflection or...
8
MMcCarthy
by: MMcCarthy | last post by:
Type MemSize RetVal of VarType() Declaration Char Conversion Boolean 2b vbBoolean(11) CBool() Byte 1b vbByte(17) ...
1
by: Kami | last post by:
I spent ALL day playing with named parameters instead of positional parameters to functions, and ended up throwing it all away. C just doesn't make that easy or clean. But the basic gist of what...
0
by: Graham | last post by:
I'm trying to write a CGI script in C#; it receives data from an HTML form via the POST method, and tries to read the form data using System.Environment.GetEnvironmentVariable(). Which is where I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.