473,498 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Type name from Variable

Hi friends,
I want to print data type name of some variables...
there is a function called typeof(var) which returns data type of var
but want to print it so i need the result in char* format
is there any method for that??

Please help me out

Mar 28 '07 #1
10 2914
On 28 Mar 2007 00:25:07 -0700, "ro********@gmail.com"
<ro********@gmail.comwrote:
>Hi friends,
I want to print data type name of some variables...
there is a function called typeof(var) which returns data type of var
but want to print it so i need the result in char* format
is there any method for that??
There is no way to do this in Standard C. gcc implements this as an
extension, but even at that, I don't think it does what you want.

If you can print what you desire from "typeof", then surely you must
have access to and are able to modify the source code. If so, why on
Earth would you want to print out the type of a variable? Certainly
the source code tells you unambiguously what the type is. In C, unlike
in some other languages, the true type of an object is always known at
compile time.

If you could provide more details on what you are trying to
accomplish, perhaps we could give you some good advice.
Best regards
--
jay
Mar 28 '07 #2
Actually i m trying to write a preprocessor,
In that preprocessor i m replacing any assignment with a macro which
logs the assignment in a logfile..

in that for logging purpose, i need to know the type of rvalue n
lvalue..
any solution for this??

Mar 28 '07 #3
"ro********@gmail.com" <ro********@gmail.comwrote:
# Hi friends,
# I want to print data type name of some variables...
# there is a function called typeof(var) which returns data type of var
# but want to print it so i need the result in char* format
# is there any method for that??

There is no ANSI C solution, and precious few nonstandard solutions.
Objective-C does have this extension as one of their @-thingies.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Haven't you ever heard the customer is always right?
Mar 28 '07 #4
Ok can anyone tell me if GNU gcc offers any symbol table functions ??

Mar 28 '07 #5
"ro********@gmail.com" <ro********@gmail.comwrote:
# Ok can anyone tell me if GNU gcc offers any symbol table functions ??

It doesn't. It can write symbol table to the object file for debuggers
if you want to decode that.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Don't say anything. Especially you.
Mar 28 '07 #6
"ro********@gmail.com" <ro********@gmail.comwrites:
Ok can anyone tell me if GNU gcc offers any symbol table functions ??
Yes, the gcc documentation can tell you that; failing that, try
gnu.gcc.help.

--
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."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 28 '07 #7
typeof(var) returns data type of the var
so can we have something like this..
#define typestring(X) #X

...
int a;
char *type = typestring(typeof(a));
....

but this is not working...
macro returns string typeof(a) ..
i want to pass result of typeof(a) to the macro
how can we do that?

Mar 29 '07 #8
On Mar 29, 3:10 pm, "rohitjo...@gmail.com" <rohitjo...@gmail.com>
wrote:
typeof(var) returns data type of the var
It might on your systems, but it is not a standard
C function. As such, we cannot assist you with it
in comp.lang.c.

BTW, please quote relevant context when replying.

--
Peter

Mar 29 '07 #9
"ro********@gmail.com" <ro********@gmail.comwrites:
typeof(var) returns data type of the var
[...]

No, it doesn't, at least not in standard C.

--
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."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 29 '07 #10
"ro********@gmail.com" <ro********@gmail.comwrote:
# typeof(var) returns data type of the var
# so can we have something like this..
#
#
# #define typestring(X) #X

#defines and all that occur prior to parsing.

# char *type = typestring(typeof(a));

The typeof can only makes sense as the context
sensitive parsing occurs.

# but this is not working...
# macro returns string typeof(a) ..

Because typeof(a) could not be evaluated during preprocessing.

This is why _function_ is character string variable, not a #define.
It requires information from the parser not available to the
preprocessor.

# i want to pass result of typeof(a) to the macro
# how can we do that?

You're screwed. Sorry. You need a parser that is willing to
share this information; except gnu objective-c, I don't know
any other parser that does this. I don't know of any parser
that even generates old-fashionned cross-reference output
that you could use for this.

The parser obviously has this information available, and if made
available would solve var-args induced bugs, but it simply isn't
done. (Historical inertia?)

--
SM Ryan http://www.rawbw.com/~wyrmwif/
What kind of convenience store do you run here?
Mar 29 '07 #11

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

Similar topics

4
4229
by: Andres | last post by:
Hi all, I have the problem to assign a variable of type object to a specific class at runtime. I want to use a string variable that specify the class a want to set this object. Is something...
7
1489
by: William Apple | last post by:
Despite the fact this deals with webservices I believe it is a VB question. I am working on a test application that passes data to a webservice. The webservices takes a variable type that is...
3
3176
by: Jon | last post by:
I'm learning about datatables. When using the example provided by MS in the ..NET Framework Class Library for DATATABLE (see below) I get an error on line 3 that says "Type expected". Is something...
13
12358
by: Don | last post by:
How do I get an Enum's type using only the Enum name? e.g. Dim enumType as System.Type Dim enumName as String = "MyEnum" enumType = ???(enumName)
2
1793
by: leo2100 | last post by:
Hi, I need help with this program. The program is supposed to take a text file and identify the words in it, then it should print them and count how many times a word is repeated. At first main...
8
1809
by: pozz | last post by:
In my software, there are some variables that represents some settings. They usually are numerical variables: unsigned char (0..255), signed char (-127..128), unsigned int (0..65535), signed int...
17
3999
by: The Frog | last post by:
Hello everyone, I am working on an application that can build database objects in MS Access from text files. I suppose you could call it a backup and restore type routine. Accessing the...
5
1349
by: pinkfloydfan | last post by:
Hi there I have the following situation...I want to perform an operation on an Enum parameter but I don't know which one of a number of Enums it will be on. The function would include...
11
3651
by: Neo | last post by:
If i have a : typedef struct str32{ uint32_t word1; uint32_t word2; } word_array; word_array *my_array; what would be the data type of this: myarray->word1
2
30791
by: nicstel | last post by:
Hello, I'm trying to find documentation about the xlwt (py_excelerator). I want to change the border of some cells. But the only types that I found is: double and dashed. How to do a simple line...
0
6993
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7162
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7197
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6881
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4584
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.