473,503 Members | 1,787 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

declaring union

21 New Member
how do you declare a union with a defined union?
Nov 5 '08 #1
8 1787
JosAH
11,448 Recognized Expert MVP
Say what?

kind regards,

Jos
Nov 5 '08 #2
stdvu
21 New Member
lollllllz

well i was supposed to write a code which i have written but the last statement in the exercise was something i didnt understand .... and that is

Declare another union of the same constitution using the previously defined Union.
Nov 5 '08 #3
stdvu
21 New Member
I was supposed to define a union as a datatype suppose i gave it a name as store now how am i suppose to declare another union with this named union??
Nov 5 '08 #4
Banfa
9,065 Recognized Expert Moderator Expert
You mean you did something like this

Expand|Select|Wrap|Line Numbers
  1. struct MyStruct {
  2.    int SomeData;
  3. } StructInstance1;
  4.  
To declare another data store all I need to do is

Expand|Select|Wrap|Line Numbers
  1. struct MyStruct StructInstance2;
  2.  
Only of course you would need to use unions.
Nov 5 '08 #5
stdvu
21 New Member
oh ok ...... thanks!
Nov 5 '08 #6
stdvu
21 New Member
ok so if i write it like this

#include <stdio.h>

typedef union
{
int a;
char b;
}data;
union data data1;


is it fine?

the ques was actually this

Define a union that can store both char and int type data values. You need to define that in a way such that later, the union name can be used as a data type itself. Declare another union of the same constitution using the previously defined Union.

Sorry but m totally new to C and home based student so having a lot of problem studying myself ..... sorry for asking too many ques
Nov 5 '08 #7
arnaudk
424 Contributor
define that in a way such that later, the union name can be used as a data type itself.
The way I read it, this means you should be able to declare another union using a single type specifier. In other words, use a typedef just like you did and then you can declare more unions like this:

data unioninstance

(because of the typedef, "data" can be used as a type in itself and doesn't need to be preceded by the "union" keyword.)
Nov 5 '08 #8
stdvu
21 New Member
thanks ! :) thanks for all your help..
Nov 5 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
8126
by: Simon Elliott | last post by:
I'd like to do something along these lines: struct foo { int i1_; int i2_; }; struct bar {
6
3317
by: Neil Zanella | last post by:
Hello, I would like to know what the C standards (and in particular the C99 standard) have to say about union initializers with regards to the following code snippet (which compiles fine under...
2
4342
by: Barry Schwarz | last post by:
Given a union of the form union { T1 m1; T2 m2;}obj; where T1 and T2 are different scalar (non-aggregate) types. The C99 standard states that obj.m1 = value; if (obj.m2 ... invokes...
10
5048
by: Denis Pithon | last post by:
Hi, C lovers! I stuck on an union problem Here is snippet of my code .... /* two pointers of function with repsectively one and two argues */ typedef int (*dce_sn_f)(dce_t*);
2
5037
by: Peter Dunker | last post by:
Hi, I will write ANSI C89. Is the following struct defenition correct ? I wrote it with VC6(Windows IDE) and at first no Problem. As I changed a compiler switch to 'no language extension', the...
73
3942
by: Sean Dolan | last post by:
typedef struct ntt { int type; union { int i; char* s; }; }nt; nt n; n.i = 0;
4
2928
by: Girish | last post by:
I have 2 differesnt defination of same Union as below and a piece of code for printing size of Union and its members.. union U { union U { int i; int j; }a;
30
3226
by: Yevgen Muntyan | last post by:
Hey, Why is it legal to do union U {unsigned char u; int a;}; union U u; u.a = 1; u.u; I tried to find it in the standard, but I only found that
5
3815
by: wugon.net | last post by:
question: db2 LUW V8 UNION ALL with table function month() have bad query performance Env: db2 LUW V8 + FP14 Problem : We have history data from 2005/01/01 ~ 2007/05/xx in single big...
0
7199
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,...
0
7074
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
7322
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
6982
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
7451
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
3161
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
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
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...

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.