Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c > #1834

Re: Tracking and Reporting Effective Type

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Wojtek Lerch <wojtek_l@yahoo.ca>
Newsgroups comp.std.c
Subject Re: Tracking and Reporting Effective Type
Date Sun, 13 Jan 2013 23:48:35 -0500
Lines 36
Message-ID <alhgt2Fme55U1@mid.individual.net> (permalink)
References <kcovdt$1ef$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net IPdoWZa1Ey9LWLf8+T2tNQw4OsxVL8J6Nc0lbFKTgqMSfhZRH51zJbNoAoyPhp5Ubz
Cancel-Lock sha1:ZHUWbklbb4eSKWQjkGEUD7WusEE=
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2
In-Reply-To <kcovdt$1ef$1@dont-email.me>
Xref csiph.com comp.std.c:1834

Show key headers only | View raw


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


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