Hi All,
I would like you help me in creating an array of data types.
I am interested in look at the the data type which looks like this
Array a[10]={int,float,char,int*............................. .},
so that a[0] should return me int and a[1] should return me
float..which helps me in runtime type casting.
I do not know how to create such an array. If i create so what would
be the data type of "Array".
This is basically a variable to "data type" conversion.
Or is there any better way to do this.
Looking keenly for the response..
Regards,
Madhur 15 8382
Madhur wrote:
Hi All,
I would like you help me in creating an array of data types.
I don't think I can do that...
I am interested in look at the the data type which looks like this
Array a[10]={int,float,char,int*............................. .},
What the **** does that mean?
so that a[0] should return me int and a[1] should return me
float..which helps me in runtime type casting.
You could possibly do something with unions, but the idea of arrays is
that elements are essentially equivalent. If you know that a[0] is an
int, a[1] a float, etc then they should simply be individual variables,
I'd have thought.
>
I do not know how to create such an array. If i create so what would
be the data type of "Array".
This is basically a variable to "data type" conversion.
Or is there any better way to do this.
I think you should tell us what you are trying to achieve in broader
terms - your original requirement - rather than telling us how you are
trying to do it.
Mark Bluemel said:
<snip>
What the **** does that mean?
In a declaration context, it means that does is a pointer to pointer to
pointer to pointer to an object of type the.
In an expression context, it could mean that the is to be multiplied by
the value pointed to by the value pointed to by the value pointed to by
does, or it could simply mean the value pointed to by the value pointed
to by the value pointed to by the value pointed to by does.
This article was brought to you by courtesy of the Coincidentally Right
Justified Usenet Articles Association. Happily, the coincidence extends
even to the very paragraph that describes it.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Thanks for the info...
Array as referred above is list hundreds of user defined data types
and it is impossible for me to take care of it each time unless i have
an explicit hash maintained to it which i can not entertain right
now.. therefore I was looking for array of data types..which seems to
be impossible...
Yes Enumeration is the only way to go..but is there any how i can link
an index to the enum data type...say enum looks like this
typedef union enum1
{
type0,
type1,
type2,
type3
..
..
..
type n
}ENUM1;
so if get an index say 2 can i extract type2 without using type2
explicity..
in better way..is there somehow ican mention ENUM(2) and which should
get me type2????
On Jul 24, 1:34 pm, Mark Bluemel <mark_blue...@pobox.comwrote:
Madhur wrote:
Hi All,
I would like you help me in creating an array of data types.
I don't think I can do that...
I am interested in look at the the data type which looks like this
Array a[10]={int,float,char,int*............................. .},
What the **** does that mean?
so that a[0] should return me int and a[1] should return me
float..which helps me in runtime type casting.
You could possibly do something with unions, but the idea of arrays is
that elements are essentially equivalent. If you know that a[0] is an
int, a[1] a float, etc then they should simply be individual variables,
I'd have thought.
I do not know how to create such an array. If i create so what would
be the data type of "Array".
This is basically a variable to "data type" conversion.
Or is there any better way to do this.
I think you should tell us what you are trying to achieve in broader
terms - your original requirement - rather than telling us how you are
trying to do it.
Madhur wrote:
Thanks for the info...
Please don't top post.
>
On Jul 24, 1:34 pm, Mark Bluemel <mark_blue...@pobox.comwrote:
>>I think you should tell us what you are trying to achieve in broader terms - your original requirement - rather than telling us how you are trying to do it.
Array as referred above is list hundreds of user defined data types
and it is impossible for me to take care of it each time unless i have
an explicit hash maintained to it which i can not entertain right
now.. therefore I was looking for array of data types..which seems to
be impossible...
Yes Enumeration is the only way to go..but is there any how i can link
an index to the enum data type...say enum looks like this
typedef union enum1
{
type0,
type1,
type2,
type3
.
.
.
type n
}ENUM1;
so if get an index say 2 can i extract type2 without using type2
explicity..
in better way..is there somehow ican mention ENUM(2) and which should
get me type2????
I think you need an enumeration of types:-
enum TYPE {
INT,
LONG,
FLOAT,
DOUBLE,
...
};
A union of data values :-
union values {
int ival;
long lval;
float fval;
double dval;
..
};
And an array of structures :-
struct data_item {
enum TYPE type;
union values value;
};
struct data_item my_data[100];
Then you can use a switch to get the data for a particular data_item.
You could even have a really ugly macro -
#define ENUM(n) (my_data[n].type == INT)?my_data[n].value.ival: \
(my_data[n].type == LONG)?my_data[n].value.lval: \
...
Untested code etc...
On Jul 24, 2:24 pm, Mark Bluemel <mark_blue...@pobox.comwrote:
Madhur wrote:
Thanks for the info...
Please don't top post.
On Jul 24, 1:34 pm, Mark Bluemel <mark_blue...@pobox.comwrote:
>I think you should tell us what you are trying to achieve in broader terms - your original requirement - rather than telling us how you are trying to do it.
Array as referred above is list hundreds of user defined data types
and it is impossible for me to take care of it each time unless i have
an explicit hash maintained to it which i can not entertain right
now.. therefore I was looking for array of data types..which seems to
be impossible...
Yes Enumeration is the only way to go..but is there any how i can link
an index to the enum data type...say enum looks like this
typedef union enum1
{
type0,
type1,
type2,
type3
.
.
.
type n
}ENUM1;
so if get an index say 2 can i extract type2 without using type2
explicity..
in better way..is there somehow ican mention ENUM(2) and which should
get me type2????
I think you need an enumeration of types:-
enum TYPE {
INT,
LONG,
FLOAT,
DOUBLE,
...
};
A union of data values :-
union values {
int ival;
long lval;
float fval;
double dval;
..
};
And an array of structures :-
struct data_item {
enum TYPE type;
union values value;
};
struct data_item my_data[100];
Then you can use a switch to get the data for a particular data_item.
You could even have a really ugly macro -
#define ENUM(n) (my_data[n].type == INT)?my_data[n].value.ival: \
(my_data[n].type == LONG)?my_data[n].value.lval: \
...
Untested code etc...
But what is the data type of the variable which stores the result thus
returned...
which brings again back to the question...
Madhur wrote:
On Jul 24, 2:24 pm, Mark Bluemel <mark_blue...@pobox.comwrote:
>>Madhur wrote:
>>>Thanks for the info...
Please don't top post.
>>>On Jul 24, 1:34 pm, Mark Bluemel <mark_blue...@pobox.comwrote:
>>>>I think you should tell us what you are trying to achieve in broader terms - your original requirement - rather than telling us how you are trying to do it.
>>>Array as referred above is list hundreds of user defined data types and it is impossible for me to take care of it each time unless i have an explicit hash maintained to it which i can not entertain right now.. therefore I was looking for array of data types..which seems to be impossible...
>>>Yes Enumeration is the only way to go..but is there any how i can link an index to the enum data type...say enum looks like this
>>>typedef union enum1 { type0, type1, type2, type3 . . . type n }ENUM1;
>>>so if get an index say 2 can i extract type2 without using type2 explicity.. in better way..is there somehow ican mention ENUM(2) and which should get me type2????
I think you need an enumeration of types:-
enum TYPE { INT, LONG, FLOAT, DOUBLE, ...
};
A union of data values :- union values { int ival; long lval; float fval; double dval; ..
};
And an array of structures :-
struct data_item { enum TYPE type; union values value;
};
struct data_item my_data[100];
Then you can use a switch to get the data for a particular data_item. You could even have a really ugly macro -
#define ENUM(n) (my_data[n].type == INT)?my_data[n].value.ival: \ (my_data[n].type == LONG)?my_data[n].value.lval: \ ...
Untested code etc...
But what is the data type of the variable which stores the result thus
returned...
God only knows. As my "Untested code" comment suggests, I only threw the
code together, I didn't analyse it. The macro approach may well not work
worth beans - indeed it may not even compile.
which brings again back to the question...
If you have to do what I think you are trying to do, I think you will
need some big switch statements to process the data appropriately to its
type. You cannot expect to handle different data types identically.
Madhur <ma********@gmail.comwrites:
I would like you help me in creating an array of data types.
I am interested in look at the the data type which looks like this
Array a[10]={int,float,char,int*............................. .},
so that a[0] should return me int and a[1] should return me
float..which helps me in runtime type casting.
I do not know how to create such an array. If i create so what would
be the data type of "Array".
This is basically a variable to "data type" conversion.
Or is there any better way to do this.
C has no way to represent types at execution time. The only solution
is to keep track of it yourself. This is likely to be error-prone; if
a typo causes your program to treat something as an int when it should
be treated as a float, the compiler isn't going to tell you about the
error.
You might be able to reduce the risk of errors by writing a program to
generate some of your C code for you automatically.
Or you might be better off using a language other than C.
<OT>
C++ has something called RTTI (run-time type information). I've just
told you everything I know about it. I don't know whether it will
actually solve your problem. For more information, consult a C++ book
or tutorial, or Google it. Any questions should be directed to
comp.lang.c++, *not* here.
</OT>
<OT>
Other languages might also provide helpful features; you might try
comp.lang.misc or comp.programming.
</OT>
--
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"
On Jul 25, 12:13 am, Keith Thompson <ks...@mib.orgwrote:
Madhur <madhurr...@gmail.comwrites:
I would like you help me in creating an array of data types.
I am interested in look at the the data type which looks like this
Array a[10]={int,float,char,int*............................. .},
so that a[0] should return me int and a[1] should return me
float..which helps me in runtime type casting.
I do not know how to create such an array. If i create so what would
be the data type of "Array".
This is basically a variable to "data type" conversion.
Or is there any better way to do this.
C has no way to represent types at execution time. The only solution
is to keep track of it yourself. This is likely to be error-prone; if
a typo causes your program to treat something as an int when it should
be treated as a float, the compiler isn't going to tell you about the
error.
You might be able to reduce the risk of errors by writing a program to
generate some of your C code for you automatically.
Or you might be better off using a language other than C.
<OT>
C++ has something called RTTI (run-time type information). I've just
told you everything I know about it. I don't know whether it will
actually solve your problem. For more information, consult a C++ book
or tutorial, or Google it. Any questions should be directed to
comp.lang.c++, *not* here.
</OT>
<OT>
Other languages might also provide helpful features; you might try
comp.lang.misc or comp.programming.
</OT>
--
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"
RTTI functionality can not be thought of in C, as C doesn't care about
the objects being created.
Hence the concepts of typeid does not work.
It would have been good to implement RTTI functionality in C too..
My problem has no solution in C but has in C++..
Madhur wrote:
On Jul 25, 12:13 am, Keith Thompson <ks...@mib.orgwrote:
<snip>
>-- 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"
Don't quote signatures unless you're commenting on them.
RTTI functionality can not be thought of in C, as C doesn't care about
the objects being created.
Hence the concepts of typeid does not work.
It would have been good to implement RTTI functionality in C too..
My problem has no solution in C but has in C++..
Err, and your question?
santosh <sa*********@gmail.comwrites:
Madhur wrote:
>On Jul 25, 12:13 am, Keith Thompson <ks...@mib.orgwrote:
<snip>
>>-- 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"
Don't quote signatures unless you're commenting on them.
So don't requote them.
Big hint : people tend to do as you do. You don't win any clc points by
taking over from Falconer as the biggest boorish fool to net nanny in
this group.
>
>RTTI functionality can not be thought of in C, as C doesn't care about the objects being created. Hence the concepts of typeid does not work. It would have been good to implement RTTI functionality in C too.. My problem has no solution in C but has in C++..
Err, and your question?
I have one. Why did you bother to reply?
On Jul 24, 3:25 am, Madhur <madhurr...@gmail.comwrote:
Hi All,
I would like you help me in creating an array of data types.
I am interested in look at the the data type which looks like this
Array a[10]={int,float,char,int*............................. .},
so that a[0] should return me int and a[1] should return me
float..which helps me in runtime type casting.
I do not know how to create such an array. If i create so what would
be the data type of "Array".
This is basically a variable to "data type" conversion.
Or is there any better way to do this.
Looking keenly for the response..
It would help to know what the larger problem you're trying to solve
is. Why do you need such a structure? You mention runtime type
casting; what are you casting, and why are you casting it?
It's not possible to build an array of types in C; what you can do is
build an array of records, each of which describes a type:
enum TypeKey {UCHAR = 0, TYPE_FIRST = UCHAR, CHAR, USHORT, SHORT,
UINT, INT, ULONG, LONG, FLOAT, DOUBLE, ..., TYPE_LAST = ...};
struct typeRecord {
char *name;
size_t size;
...
};
typeRecord typeArr[TYPE_LAST - TYPE_FIRST];
typeArr[UCHAR].name = "unsigned char";
typeArr[UCHAR].size = sizeof (unsigned char);
typeArr[UCHAR]... /* any additional properties */
typeArr[CHAR].name = "char";
typeArr[CHAR].size = sizeof (char);
....
etc., etc., etc.
Again, without knowing what the actual problem you're trying to solve
is, we can't really be much help.
Richard wrote:
santosh <sa*********@gmail.comwrites:
>Madhur wrote:
>>On Jul 25, 12:13 am, Keith Thompson <ks...@mib.orgwrote:
<snip>
<snip>
>Don't quote signatures unless you're commenting on them.
So don't requote them.
If the OP is new to Usenet, he might not know what a signature is, hence I
placed my comments just below one, as a hint.
santosh wrote:
Richard wrote:
santosh <sa*********@gmail.comwrites:
Madhur wrote:
> On Jul 25, 12:13 am, Keith Thompson <ks...@mib.orgwrote:
>
<snip>
<snip>
Don't quote signatures unless you're commenting on them.
So don't requote them.
If the OP is new to Usenet
Is it not blindingly obvious by now that Richard is a troll? Why
respond to this sort of thing?
Brian
Default User wrote:
Is it not blindingly obvious by now that Richard is a troll? Why
respond to this sort of thing?
It's a little more complex than that. I struggled for a while with
whether or not to killfile Richard, and checked in Google Groups to see
whether he actually posted useful stuff at all. The evidence there
seemed to indicate that he did, so I left it.
Then I concluded that the signal to noise ratio for his postings dropped
below my threshold...
Mark Bluemel <ma**********@pobox.comwrites:
Default User wrote:
>Is it not blindingly obvious by now that Richard is a troll? Why respond to this sort of thing?
It's a little more complex than that. I struggled for a while with
whether or not to killfile Richard, and checked in Google Groups to
see whether he actually posted useful stuff at all. The evidence there
seemed to indicate that he did, so I left it.
Then I concluded that the signal to noise ratio for his postings
dropped below my threshold...
OT. Not relevant to this NG. Blah Blah Blah. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: J. Campbell |
last post by:
I have a feeling that I'm doing things all ass-backwards (again ;-),
and would like some advice. What I want to do is:
put some data to memory and then access that memory space as an array
of...
|
by: billy |
last post by:
I've got a set of subclasses that each derive from a common base class. What
I'd
like to do is create a global array of the class types (or, class names)
that a manager
class can walk through in...
|
by: richard |
last post by:
I'd like to have an array in which the elements are various data types.
How do I do this in Python?
For example:
array.artist = 'genesis'
array.album = 'foxtrot'
array.songs =
array.artist...
|
by: Chris Travers |
last post by:
Hi all;
I just made an interesting discovery. Not sure if it is a good thing or
not, and using it certainly breakes first normal form.... Not even sure if
it really works. However, as I am...
|
by: theshowmecanuck |
last post by:
As a matter of academic interest only, is there a way to programmatically
list the 'c' data types? I am not looking for detail, just if it is
possible, and what function could be used to...
|
by: xmail123 |
last post by:
Hi,
Hi,
As was pointed out whatever you return from a WebMethod needs to be
serializable to SOAP. An ArrayList is not serializable. I will be
needing to return other data types from web...
|
by: xmail123 |
last post by:
Hi,
As was pointed out whatever you return from a WebMethod needs to be
serializable to SOAP. An ArrayList is not serializable. I will be
needing to return other data types from web methods. ...
|
by: mike.griffin |
last post by:
If you look at this web page you'll see that pg_contraint has a column
named confkey. It's an array of type int2 that maps back to
pg_attribute.attnum to get the columns involved in the foreign...
|
by: Madhur |
last post by:
Hi All,
I would like you help me in creating an array of data types.
I am interested in look at the the data type which looks like this
Array...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |