Hi,
I am pretty sure this is not possible, but maybe somehow it is.
Given a variable, can I tell what type it is at runtime?
Michael 26 2430
On Sat, 13 Nov 2004, Michael McGarry wrote: Given a variable, can I tell what type it is at runtime?
Sure. Just take the type it was at compile time, and remember it.
For example,
int main(void)
{
int i;
printf("i is of type %s.\n", "int");
return 0;
}
If you have some other idea in mind, you're going to have to be more
explicit.
-Arthur
On Sun, 14 Nov 2004 04:28:36 UTC, Michael McGarry
<mm******@nospa m.org> wrote: Hi,
I am pretty sure this is not possible, but maybe somehow it is.
Given a variable, can I tell what type it is at runtime?
No. Your compiler replaces names with addresses. Nothing as the human
writing the souerces needs names for variables, so the compiler
eliminates them.
--
Tschau/Bye
Herbert
Visit http://www.ecomstation.de the home of german eComStation
On Sat, 13 Nov 2004 21:28:36 -0700, in comp.lang.c , Michael McGarry
<mm******@nospa m.org> wrote: Hi,
I am pretty sure this is not possible, but maybe somehow it is. Given a variable, can I tell what type it is at runtime?
You're right - there's no typeof() operator or function in C. By runtime,
all variables are replaced by addresses etc and there's no type information
carted around with them.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Michael McGarry <mm******@nospa m.org> wrote in message news:<T9Bld.587 79$EZ.51910@oke pread07>... Hi,
I am pretty sure this is not possible, but maybe somehow it is.
Given a variable, can I tell what type it is at runtime?
Michael
By size, maybe ?...
In article <T9Bld.58779$EZ .51910@okepread 07>,
Michael McGarry <mm******@nospa m.org> wrote: Hi,
I am pretty sure this is not possible, but maybe somehow it is.
Given a variable, can I tell what type it is at runtime?
Some compilers, like gcc, provide a construct named
typeof() which produces the object type. Unfortunately,
(and inexplicably) typeof() has not found its way into
the C standard.
--
Rouben Rostamian
Rouben Rostamian wrote: In article <T9Bld.58779$EZ .51910@okepread 07>, Michael McGarry <mm******@nospa m.org> wrote:
Hi,
I am pretty sure this is not possible, but maybe somehow it is.
Given a variable, can I tell what type it is at runtime?
Some compilers, like gcc, provide a construct named typeof() which produces the object type. Unfortunately, (and inexplicably) typeof() has not found its way into the C standard.
Is there really a typeof()?? Which standard library is it in?
Michael
Michael McGarry wrote: Rouben Rostamian wrote:
In article <T9Bld.58779$EZ .51910@okepread 07>, Michael McGarry <mm******@nospa m.org> wrote:
Hi,
I am pretty sure this is not possible, but maybe somehow it is.
Given a variable, can I tell what type it is at runtime? Some compilers, like gcc, provide a construct named typeof() which produces the object type. Unfortunately, (and inexplicably) typeof() has not found its way into the C standard. Is there really a typeof()?? Which standard library is it in?
Michael
No typeof in C.
--
Joe Wright mailto:jo****** **@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
On Sun, 14 Nov 2004 21:49:14 -0500, Joe Wright wrote: Michael McGarry wrote: Rouben Rostamian wrote:
In article <T9Bld.58779$EZ .51910@okepread 07>, Michael McGarry <mm******@nospa m.org> wrote:
Hi,
I am pretty sure this is not possible, but maybe somehow it is.
Given a variable, can I tell what type it is at runtime? Some compilers, like gcc, provide a construct named typeof() which produces the object type. Unfortunately, (and inexplicably) typeof() has not found its way into the C standard. Is there really a typeof()?? Which standard library is it in?
Michael
No typeof in C.
I don't understand the confusion/sarcasm here. Rouben clearly stated it
was not standard. It is however a useful feature available to many
developers and there is no harm voicing the fact that it exists (along
with the fact that it is not standard as Rouben did) when there is no
standard solution and the information may help the OP.
Rob Gamble This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: fotzor |
last post by:
Hi,
is it somehow possible to get the type of a variable in a macro?
example:
#define SOME_MACRO(x) // what's the type of x???
i guess the type-information is lost but i can't use a template here
|
by: Ray Muforosky |
last post by:
I have this:
------------
print "<FORM name=\"form3\" ACTION=\"cmdlog_rep.php\">\n";
print "<TD><INPUT TYPE=\"submit\" VALUE=\"Submit\"></TD>\n";
..
print "<INPUT type=\"HIDDEN\" name=\"year1\" >\n";
print "<INPUT type=\"TEXT\" name=\"when\" >\n";
print "</FORM>\n";
|
by: gimme_this_gimme_that |
last post by:
Hi,
This is sort of a :
How to build a Yes/No dialog box qquestion.
Or perhaps a question about getting javascript variables
from a pop-up window and processing them on a submit.
This is what I'd like to have happen :
|
by: Mike Spertus |
last post by:
Is there a way to get an approximate stackpointer into an int in C#?
The following works, but is unsafe and adds a new variable to the
stackframe:
int i = (int)(&i);
It seems like it should be possible to do this safely because I never
dereference a pointer. Perhaps there is a safe way to load a register
value into an int?
|
by: Shawnk |
last post by:
I would like to get the class INSTANCE name (not type name) of an
'object'.
I can get the object (l_obj_ref.GetType()) and then get the
(l_obj_typ.Name) for the class name.
I there any way of getting 'l_Fred_my_ins' out of the following.
....
My_cls l_Fred_my_ins = new My_cls();
| |
by: R.Manikandan |
last post by:
Hi
In my code, one string variable is subjected to contain more amount of
characters. If it cross certain limit, the string content in the
varabile is automatically getting truncated and i am not getting the
full data.
Is there any max limit for an variable to store in javascript?
Can anyone please help me to solve this prob?
|
by: Jim |
last post by:
Hi guys,
I have an object which represents an "item" in a CMS "component" where
an "item" in the most basic form just a field, and a "component" is
effectively a table.
"item" objects can be created and then added to "component" objects to
build up the component definition.
My dilemma comes in deciding how to read/write data to the "item"
|
by: simbarashe |
last post by:
Hie
could someone please help me with getting and using the current page url. I have a function that gets the url, I want to use it with header(location : XXX) but it wont work. The code is as follows:
The code below is for the first page:session_start is in line 3
<link href="css/jobSheet.css" rel="stylesheet" type="text/css" />
session_start();
|
by: ssylee |
last post by:
I am using mikroC to program some microcontroller code in C. However I
have come across of potential problem of bool type not being supported
from the compiler complaint on how I declared type bool variable. From
a forum thread that I've pulled out from mikroBasic, I realized that
bool type isn't fully supported. When programming in mikroC, I have
been getting an error message of "invalid expression" when I declared
a bool type variable,...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |