Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Newsgroups | comp.std.c |
|---|---|
| Date | 2020-11-30 10:44 -0800 |
| Message-ID | <272ec269-16e7-4e06-b8a8-e5f6534e66a8n@googlegroups.com> (permalink) |
| Subject | Assignment between union object members of incompatible types |
| From | Ian Abbott <ijabbott63@gmail.com> |
A question (not posted by myself) from https://stackoverflow.com/questions/65077630 :
Consider the following:
union { int i; char c; } x = {0};
x.c = x.i;
Does the assignment x.c = x.i result in undefined behavior?
C18 6.15.16.1/3 says:
| If the value being stored in an object is read from another object
| that overlaps in any way the storage of the first object, then the
| overlap shall be exact and the two objects shall have qualified or
| unqualified versions of a compatible type; otherwise, the behavior is
| undefined.
The objects x.c and x.i overlap, but have incompatible types, so on first glance it appears to be UB.
Back to comp.std.c | Previous | Next — Next in thread | Find similar | Unroll thread
Assignment between union object members of incompatible types Ian Abbott <ijabbott63@gmail.com> - 2020-11-30 10:44 -0800
Re: Assignment between union object members of incompatible types James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-11-30 14:45 -0500
Re: Assignment between union object members of incompatible types Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-11-30 12:20 -0800
Re: Assignment between union object members of incompatible types Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-12-01 03:39 -0800
Re: Assignment between union object members of incompatible types Francis Glassborow <francis.glassborow@btinternet.com> - 2020-12-05 14:27 +0000
Re: Assignment between union object members of incompatible types Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-07-10 08:42 -0700
Re: Assignment between union object members of incompatible types Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-12-01 02:49 -0800
csiph-web