hello
is it possible to determine the type of an expression? something like
operator sizeof but for types...
for example:
typeof(5.0) --> returns "double"
typeof(5+7) --> returns "int"
etc. 13 1600
On 2006-03-26, fctk <-> wrote: hello
is it possible to determine the type of an expression? something like operator sizeof but for types...
for example:
typeof(5.0) --> returns "double" typeof(5+7) --> returns "int"
etc.
Since, taking a guess, there is no evidence of any type information
being stored with the object data then no.
The type information is "stored" in the handles (variables) used to
access that data : and can therefore be lost through casts,
Will be interested to hear anything different as I've never seen or
used runtime type checks in C.
On 2006-03-26, Richard G. Riley <rg****@gmail.com> wrote: On 2006-03-26, fctk <-> wrote: hello
is it possible to determine the type of an expression? something like operator sizeof but for types...
for example:
typeof(5.0) --> returns "double" typeof(5+7) --> returns "int"
etc. Since, taking a guess, there is no evidence of any type information being stored with the object data then no.
Yeah, but he's referring to the type of an expression - this is known at
compile time. The type of *(int *)&f is int, and no undefined behavior
would be invoked just like none is invoked currently when passing that
expression to the sizeof operator.
The type information is "stored" in the handles (variables) used to access that data : and can therefore be lost through casts,
Will be interested to hear anything different as I've never seen or used runtime type checks in C.
He's not talking about runtime type checks - the typeof operator works
on expressions, not blobs of memory, and is a common extension.
<fctk <->> wrote: is it possible to determine the type of an expression? something like operator sizeof but for types...
for example:
typeof(5.0) --> returns "double" typeof(5+7) --> returns "int"
There is no such language feature. However, it's important to note that
types, by definition, are ALWAYS statically determinable at compile
time, so there's never strictly a need to determine the type using an
operator. You just look at the types of the operands, and apply the
language rules to determine the resulting type.
Granted, though, those rules can be confusing, especially in Java 1.5.
I'm not sure it'd help to have the operator then, though, as Java 1.5
has various types that aren't even expressable in language syntax.
-- www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
On 2006-03-26, Chris Smith <cd*****@twu.net> wrote: <fctk <->> wrote: is it possible to determine the type of an expression? something like operator sizeof but for types...
for example:
typeof(5.0) --> returns "double" typeof(5+7) --> returns "int" There is no such language feature. However, it's important to note that types, by definition, are ALWAYS statically determinable at compile time, so there's never strictly a need to determine the type using an operator. You just look at the types of the operands, and apply the language rules to determine the resulting type.
Yeah, _you_ can look at it, but you can't make the compiler look at it.
#define assign_from_va(v,list) ((v)=va_next((list),typeof(v)))
#define swap(a,b) do { typeof(b) x=(a); (a)=(b); (b)=(x); } while(0)
#define member_bytes(a,b) ((unsigned char *)(&(a))+\
offsetof(typeof(a),b))
Granted, though, those rules can be confusing, especially in Java 1.5. I'm not sure it'd help to have the operator then, though, as Java 1.5 has various types that aren't even expressable in language syntax.
He doesn't want the type as a string, he wants it as something he can
use as a type to declare other variables with, or cast to, or maybe pass
to offsetof, etc.
Chris Smith <cd*****@twu.net> wrote: [Stuff about Java]
Sorry, wrong newsgroup!
-- www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
On 2006-03-26, Chris Smith <cd*****@twu.net> wrote: Chris Smith <cd*****@twu.net> wrote: [Stuff about Java]
Sorry, wrong newsgroup!
I thought you were talking about Java by analogy, since types _aren't_
always statically determinable in Java itself [unless you want to be
stuck thinking of something as an Object.]
On 2006-03-26, Jordan Abel <ra*******@gmail.com> wrote: On 2006-03-26, Richard G. Riley <rg****@gmail.com> wrote: On 2006-03-26, fctk <-> wrote: hello
is it possible to determine the type of an expression? something like operator sizeof but for types...
for example:
typeof(5.0) --> returns "double" typeof(5+7) --> returns "int"
etc.
Since, taking a guess, there is no evidence of any type information being stored with the object data then no.
Yeah, but he's referring to the type of an expression - this is known at compile time. The type of *(int *)&f is int, and no undefined behavior would be invoked just like none is invoked currently when passing that expression to the sizeof operator.
The type information is "stored" in the handles (variables) used to access that data : and can therefore be lost through casts,
Will be interested to hear anything different as I've never seen or used runtime type checks in C.
He's not talking about runtime type checks - the typeof operator works on expressions, not blobs of memory, and is a common extension.
There was nothing to say he was referring to compile time only was
there ? That is clear since the handles have that type information -
its why types and implicit conversions exist - as you pointed out.
On 2006-03-26, Richard G. Riley <rg****@gmail.com> wrote: On 2006-03-26, Jordan Abel <ra*******@gmail.com> wrote: On 2006-03-26, Richard G. Riley <rg****@gmail.com> wrote: On 2006-03-26, fctk <-> wrote: hello
is it possible to determine the type of an expression? something like operator sizeof but for types...
for example:
typeof(5.0) --> returns "double" typeof(5+7) --> returns "int"
etc.
Since, taking a guess, there is no evidence of any type information being stored with the object data then no.
Yeah, but he's referring to the type of an expression - this is known at compile time. The type of *(int *)&f is int, and no undefined behavior would be invoked just like none is invoked currently when passing that expression to the sizeof operator.
The type information is "stored" in the handles (variables) used to access that data : and can therefore be lost through casts,
Will be interested to hear anything different as I've never seen or used runtime type checks in C.
He's not talking about runtime type checks - the typeof operator works on expressions, not blobs of memory, and is a common extension.
There was nothing to say he was referring to compile time only was there ? That is clear since the handles have that type information - its why types and implicit conversions exist - as you pointed out.
An expression is a compile-time construct, though.
fctk wrote: hello
is it possible to determine the type of an expression? something like operator sizeof but for types...
for example:
typeof(5.0) --> returns "double" typeof(5+7) --> returns "int"
No. Though you can figure out the type of an expression by carefully
applying the rules of C, there is no provision in the language or the
library to determine the type of an object. I suppose you mean
something analogous to RTTI in C++, but there is no such thing in C.
fctk 写道: hello
is it possible to determine the type of an expression? something like operator sizeof but for types...
for example:
typeof(5.0) --> returns "double" typeof(5+7) --> returns "int"
etc.
hi,in the book named exceptional c++ has the code you needed,because
they are not simple ,i can't write all of them here .you can check the
book for help.
My best!
threes
On 26 Mar 2006 17:47:41 -0800, "lostpencil" <sp************@gmail.com>
wrote in comp.lang.c: fctk ???
hello
is it possible to determine the type of an expression? something like operator sizeof but for types...
for example:
typeof(5.0) --> returns "double" typeof(5+7) --> returns "int"
etc.
hi,in the book named exceptional c++ has the code you needed,because they are not simple ,i can't write all of them here .you can check the book for help.
But since this is comp.lang.c, your answer is completely meaningless,
and the book is not relevant at all.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jordan Abel <ra*******@gmail.com> writes: An expression is a compile-time construct, though.
(Ignoring issues with variably modified types.)
On 2006-03-27, Micah Cowan <mi***@cowan.name> wrote: Jordan Abel <ra*******@gmail.com> writes:
An expression is a compile-time construct, though.
(Ignoring issues with variably modified types.)
It's still not an "expression" anymore at runtime, it's just code like
any other code. _most_ expressions are evaluated at runtime, not just
those involving variably modified types, but an expression is
a syntactic construct, not a functional one. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Yuriy Solodkyy |
last post by:
Hi
VS 2005 beta 2 successfully compiles the following:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1 {
class Program {
|
by: Xah Lee |
last post by:
in March, i posted a essay “What is Expressiveness in a Computer
Language”, archived at:
http://xahlee.org/perl-python/what_is_expresiveness.html
I was informed then that there is a academic...
|
by: Alex Vinokur |
last post by:
Why does one need to use two kinds of sizeof operator:
* sizeof unary-expression,
* sizeof (type-name)
?
Their behavior seem not to be different (see an example below).
------ C++ code...
|
by: mario |
last post by:
Hi!
First of all, sorry for my English, it's not my native tongue.
Anyway, here we go:
suppose I create a class that handles my own custom text strings.
No, suppose I create TWO such classes,...
|
by: Protoman |
last post by:
Read this code I found on the Internet:
Object o,*oo; // Some objects
int (Object::*ptr_to_o_func)(double);
// ptr_to_obj_func is a pointer to a
// member function of Object
oo =...
|
by: urkel |
last post by:
Hi everyone,
I critically need help to solve this problem related to pointer in C++
Basically, I have a C/C++ program "retardselfenerg" calling a Fortran 90 subroutine "surfGF4.f90". i am so...
|
by: not_a_commie |
last post by:
It seems that the only way to construct a struct from a type is to use
Activator.CreateInstance. Is that true? Can anyone improve
(performance-wise) upon this function below:
/// <summary>...
|
by: bob_jenkins |
last post by:
In C# 2.0, given an arbitrary expression and the types of the
variables referenced in it, how do I find the expression type? For
example,
int x;
float y;
what is the type of x+y?
If I had...
|
by: Ranganath |
last post by:
Hi,
Why is there a restriction that only integral types can be made static
constant members of a class?
For e.g.,
class B {
private:
static const double K = 10;
};
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
|
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...
| |