473,399 Members | 3,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

union usage

The following was labeled as invoking undefined behavior
but I don't see that happening at all:

struct ints {
int a;
int b;
};

union merge {
float f;
struct ints typ;
};

union merge i;
union merge j;

i.f = 1;
j = i; /* means j.f = 1 ? */

i.typ.a = i.typ.b = 0; /* we assign here, we are not reading the value
of i.type.b */
j = i; /* means j.typ.a = j.typ.b = 0 ? */
This is all valid, right?

--
j0mbolar

Dec 27 '05 #1
5 3354
j0mbolar wrote:
The following was labeled as invoking undefined behavior
but I don't see that happening at all:

struct ints {
int a;
int b;
};

union merge {
float f;
struct ints typ;
};

union merge i;
union merge j;

i.f = 1;
j = i; /* means j.f = 1 ? */

i.typ.a = i.typ.b = 0; /* we assign here, we are not reading the value
of i.type.b */
j = i; /* means j.typ.a = j.typ.b = 0 ? */
This is all valid, right?


Looks all right to me.

--
Eric Sosman
es*****@acm-dot-org.invalid
Dec 27 '05 #2
i also think it works right

Dec 28 '05 #3
j0mbolar <j0******@engineer.com> wrote:
The following was labeled as invoking undefined behavior
but I don't see that happening at all:

struct ints {
int a;
int b;
};

union merge {
float f;
struct ints typ;
};

union merge i;
union merge j;

i.f = 1;
j = i; /* means j.f = 1 ? */

i.typ.a = i.typ.b = 0; /* we assign here, we are not reading the value
of i.type.b */
Isn't the value of the object `i.typ' in the above line modified twice
without an intervening sequence point (cf. 6.5#2)?
j = i; /* means j.typ.a = j.typ.b = 0 ? */
This is all valid, right?


--
Stan Tobias
mailx `echo si***@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`
Dec 28 '05 #4
S.Tobias wrote:
j0mbolar <j0******@engineer.com> wrote:
The following was labeled as invoking undefined behavior
but I don't see that happening at all:

struct ints {
int a;
int b;
};

union merge {
float f;
struct ints typ;
};

union merge i;
union merge j;

i.f = 1;
j = i; /* means j.f = 1 ? */

i.typ.a = i.typ.b = 0; /* we assign here, we are not reading the value
of i.type.b */


Isn't the value of the object `i.typ' in the above line modified twice
without an intervening sequence point (cf. 6.5#2)?


Since you are modifying different fields within the struct, I can't see
that that would apply.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Dec 28 '05 #5
Flash Gordon <sp**@flash-gordon.me.uk> wrote:
S.Tobias wrote:
j0mbolar <j0******@engineer.com> wrote:
The following was labeled as invoking undefined behavior
but I don't see that happening at all:

struct ints {
int a;
int b;
};

union merge {
float f;
struct ints typ;
};

union merge i;
union merge j;

i.f = 1;
j = i; /* means j.f = 1 ? */

i.typ.a = i.typ.b = 0; /* we assign here, we are not reading the value
of i.type.b */


Isn't the value of the object `i.typ' in the above line modified twice
without an intervening sequence point (cf. 6.5#2)?


Since you are modifying different fields within the struct, I can't see
that that would apply.


[blushing] Right, I'm sorry, I thought `i.typ' was a union; must buy glasses.

--
Stan Tobias
mailx `echo si***@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`
Dec 28 '05 #6

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

Similar topics

3
by: Matias Silva | last post by:
Hi Everyone, I wrote a for loop to build several select statements that are combined with a UNION. When I execute one of the queries separately, it works, but when I execute the query with a UNION...
8
by: lyn.duong | last post by:
Hi, I have a large table (about 50G) which stores data for over 7 years. I decided to split this table up into a yearly basis and in order to allow minimum changes to the applications which...
73
by: Sean Dolan | last post by:
typedef struct ntt { int type; union { int i; char* s; }; }nt; nt n; n.i = 0;
6
by: Scott Kilpatrick | last post by:
Let's say I have a hacked-up polymorphic container that holds variables of type: struct poly { union { int *i; double *d; complex<double> *c; } value; char type;
2
by: balasam | last post by:
I want what is the application of union in C.Please explain
3
by: PickwickBob3 | last post by:
I am try to marshall the following: /*typedef struct tagRAWMOUSE { USHORT usFlags; union { ULONG ulButtons; struct { USHORT usButtonFlags;
10
by: piboye | last post by:
Hi ! I'm a academician in china. I have been intereted in C++ lasting. In reading the C++ Primer book, i have a trouble about union. In the book ,it said that union can have constructors and...
5
by: BillCo | last post by:
I've encountered a problem while using ADO to save query objects. Union queries created normally (via the interface) appear in adox catelog.procedures rather than catelog.views. This is reasonably...
4
by: Theo R. | last post by:
Hi all, I have the following struct defined - #define INTEGER 0 #define STRING 1 typedef struct { char type ; union {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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
agi2029
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 project—planning, coding, testing,...

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.