POV-Ray : Newsgroups : povray.off-topic : This is the sort of brokenness... : Re: This is the sort of brokenness... Server Time
6 Sep 2024 11:17:13 EDT (-0400)
  Re: This is the sort of brokenness...  
From: Warp
Date: 21 Mar 2009 07:42:10
Message: <49c4d292@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> Warp wrote:
> >   You can't access the private variable by address. Not according to the
> > standard. 

> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1905.pdf
> Section 3.9 paragraph 2, page 60 sheet 74.

> #define N sizeof(T)
> char buf[N];
> T obj ; // obj initialized to its original value
> std::memcpy(buf, &obj, N); // between these two calls to std::memcpy,
>                             // obj might be modified
> std::memcpy(&obj, buf, N); // at this point, each subobject of obj of scalar 
> type
> // holds its original value


> Yet I'm sure at this point that there will be some reason this doesn't count 
> as violating modularity. Will it be that it's only a draft of the standard? 
> Will it be that it's only true of POD types? Will it be because it only says 
> it works for reading and writing all the private variables at once?

  By the same logic this would also "break modularity":

T obj;
T obj2 = obj;

  All the data in obj is copied to obj2. This includes all the private data.

  However, the memcpy() version *is* breaking modularity because, as the
text says, it's guaranteed to work only if the object contains scalar
types. If you assume it does, you are breaking modularity.

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.