473,890 Members | 1,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating array of data types

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,cha r,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

Jul 24 '07 #1
15 8458
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,cha r,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.
Jul 24 '07 #2
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
Jul 24 '07 #3
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...@p obox.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,cha r,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.

Jul 24 '07 #4
Madhur wrote:
Thanks for the info...
Please don't top post.
>
On Jul 24, 1:34 pm, Mark Bluemel <mark_blue...@p obox.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...
Jul 24 '07 #5
On Jul 24, 2:24 pm, Mark Bluemel <mark_blue...@p obox.comwrote:
Madhur wrote:
Thanks for the info...

Please don't top post.


On Jul 24, 1:34 pm, Mark Bluemel <mark_blue...@p obox.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...

Jul 24 '07 #6
Madhur wrote:
On Jul 24, 2:24 pm, Mark Bluemel <mark_blue...@p obox.comwrote:
>>Madhur wrote:
>>>Thanks for the info...

Please don't top post.

>>>On Jul 24, 1:34 pm, Mark Bluemel <mark_blue...@p obox.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.
Jul 24 '07 #7
Madhur <ma********@gma il.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,cha r,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.programmin g.
</OT>

--
Keith Thompson (The_Other_Keit h) 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"
Jul 24 '07 #8
On Jul 25, 12:13 am, Keith Thompson <ks...@mib.orgw rote:
Madhur <madhurr...@gma il.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,cha r,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.programmin g.
</OT>

--
Keith Thompson (The_Other_Keit h) 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++..

Jul 25 '07 #9
Madhur wrote:
On Jul 25, 12:13 am, Keith Thompson <ks...@mib.orgw rote:
<snip>
>--
Keith Thompson (The_Other_Keit h) 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?

Jul 25 '07 #10

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

Similar topics

1
2079
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 data-types of my choosing (eg an array of char, short, or int). The application has to do with generating checksum-type values for files or strings, so speed is important, as I just want to quickly get this value then move on to the next task. As...
6
2377
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 its constructor and instantiate one of each of the class types in this global array. So, it's almost like the global array has to hold data types as opposed to data. Basically, I currently have to add the items manually 1 at a time.
7
2146
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 = 'beatles' array.album = 'abbey road'
17
3176
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 able to CRASH the backend, there is a bug here somewhere... test=# select version(); version
11
3197
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 accomplish it. For example: int main void() { while there are more data types { print next data type; }
0
1547
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 methods. Is there a document, or can some one list those types that are not serializable and the syntax for converting them?
8
6326
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. Is there a document, or can some one list those types that are not serializable and the syntax for converting them? Thanks
0
1224
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 key, how do I use these array types, I need to bind back to pg_attribute and get the list of columns, do I need to pull that data back, parse it in my application code and hit pg_attribute with an IN clause or something? ...
1
369
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 a={int,float,char,int*..............................}, so that a should return me int and a should return me float..which helps me in runtime type casting.
0
9978
marktang
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...
0
9819
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,...
0
11222
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, 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...
0
10811
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10919
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,...
1
8015
isladogs
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...
0
5846
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6041
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3275
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.