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


Groups > comp.std.c > #1833

Tracking and Reporting Effective Type

From Shao Miller <sha0.miller@gmail.com>
Newsgroups comp.std.c
Subject Tracking and Reporting Effective Type
Date 2013-01-11 07:09 -0500
Organization A noiseless patient Spider
Message-ID <kcovdt$1ef$1@dont-email.me> (permalink)

Show all headers | View raw


Good day to All.

   "The effective type of an object for an access to its stored value is 
the declared type of the object, if any.87) If a value is stored into an 
object having no declared type through an lvalue having a type that is 
not a character type, then the type of the lvalue becomes the effective 
type of the object for that access and for subsequent accesses that do 
not modify the stored value. If a value is copied into an object having 
no declared type using memcpy or memmove, or is copied as an array of 
character type, then the effective type of the modified object for that 
access and for subsequent accesses that do not modify the value is the 
effective type of the object from which the value is copied, if it has 
one. For all other accesses to an object having no declared type, the 
effective type of the object is simply the type of the lvalue used for 
the access."

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:

   #include <stdlib.h>

   #define obj_sz (sizeof (float))

   float test(float f) {
       void * ptr;
       unsigned char * src;
       unsigned char * trgt;
       size_t i;
       float new_float;

       ptr = malloc(obj_sz);
       if (!ptr)
         return 0.0f;

       src = (void *) &f;
       trgt = ptr;
       for (i = 0; i < obj_sz; ++i) {
           if (src[i] + 0 == src[i])
             trgt[i] = src[i] + 0;
             else
             return 0.0f;
         }

       /*
        * What is the effective type of the storage
        * pointed-to by 'ptr'?  Is the following
        * access via indirection a violation of 6.5p7?
        */
       new_float = *(float *) ptr;

       free(ptr);
       return new_float;
     }

   int main(void) {
       test(3.14f);
       return EXIT_SUCCESS;
     }

Intuitively, I'd like to answer "float" and "no" to the two questions in 
the comment, but I'm not 100% sure.  Does the population of the 
allocated storage qualify for "copied" in the Standard paragraph, above?

-- 
- Shao Miller
--
"Thank you for the kind words; those are the kind of words I like to hear.

Cheerily,"  -- Richard Harter

Back to comp.std.c | Previous | Next — 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