Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Wojtek Lerch <wojtek_l@yahoo.ca> |
|---|---|
| Newsgroups | comp.std.c |
| Subject | Re: Tracking and Reporting Effective Type |
| Date | 2013-01-13 23:48 -0500 |
| Message-ID | <alhgt2Fme55U1@mid.individual.net> (permalink) |
| References | <kcovdt$1ef$1@dont-email.me> |
On 11/01/2013 7:09 AM, Shao Miller wrote:
> I'm planning on writing implementation code that tracks and reports
> effective type, whenever possible, as a "bonus" feature. I've run into
> a challenge:
I have another challenge for you:
union u {
struct sl { int16_t s; int32_t l; } sl;
struct ls { int32_t l; int16_t s; } ls;
uint32_t u;
float f;
};
int main(void) {
void *p;
if ( sizeof(union u) == 6 // no padding
&& ( m = malloc(6) ) != NULL ) {
union u u;
memset( u, 0, 6 );
memcpy( p, (void*)&u.sl, 6 );
...
}
}
At the "...", does the 6-byte object that p points to have an effective
type? Is it union u, struct sl, or perhaps struct ls? Would the answer
change if the second argument of the memcpy were (void*)&u instead of
(void*)&u.sl? Or (void*)&u.f?
Does the four-byte sub-object at the beginning of "u" have an effective
type? Is it int32_t, uint32_t, or perhaps (if sizeof(float)==4) float?
Or somehow all of the above? What about the four-byte object starting
at the byte that p points to? And the two-byte object starting at the
same byte?
Back to comp.std.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Tracking and Reporting Effective Type Shao Miller <sha0.miller@gmail.com> - 2013-01-11 07:09 -0500
Re: Tracking and Reporting Effective Type Wojtek Lerch <wojtek_l@yahoo.ca> - 2013-01-13 23:48 -0500
Re: Tracking and Reporting Effective Type Shao Miller <sha0.miller@gmail.com> - 2013-01-14 01:03 -0500
Re: Tracking and Reporting Effective Type Wojtek Lerch <wojtek_l@yahoo.ca> - 2013-01-15 00:28 -0500
Re: Tracking and Reporting Effective Type Shao Miller <sha0.miller@gmail.com> - 2013-01-15 05:39 -0500
Re: Tracking and Reporting Effective Type Wojtek Lerch <wojtek_l@yahoo.ca> - 2013-01-17 00:32 -0500
Re: Tracking and Reporting Effective Type Wojtek Lerch <wojtek_l@yahoo.ca> - 2013-01-17 01:23 -0500
Re: Tracking and Reporting Effective Type Shao Miller <sha0.miller@gmail.com> - 2013-01-17 22:47 -0500
Re: Tracking and Reporting Effective Type Wojtek Lerch <wojtek_l@yahoo.ca> - 2013-01-18 16:14 -0500
Re: Tracking and Reporting Effective Type Wojtek Lerch <wojtek_l@yahoo.ca> - 2013-01-18 16:21 -0500
csiph-web