Jim Schram <[EMAIL PROTECTED]> writes:

> Your code *does* declare a structure containing a BitmapType
> structure, who's individual field definitions are not known without
> #defining ALLOW_ACCESS_TO_INTERNALS_OF_BITMAPS. The compiler needs to
> know the BitmapType structure's size information, to compute the size
> of a _record, and thus ultimately the size of a GraphicsRecord class.

No, it *does not*, it declares a *pointer* to a structure containing a
BitmapType structure. When the compiler allocates a GraphicsRecord on
the stack, it needs to allocate 8 bytes for the following elements:

 MemHandle recordh               (a 32 bit pointer)
 struct _record { ... } * data   (another 32 bit pointer)

Look at the declaration below more carefully.  The compiler does not
need to know the size of "struct _record" in order to allocate space for
a GraphicsRecord.

> Your original code is:
> 
>  class GraphicsRecord {
>  private:
>    MemHandle recordh;
>    const struct _record {
>      UInt16 flags;
>      BitmapType bitmap;
>    }* data;

> To support your claim that it only declares a pointer to a BitmapType
> structure, 

This is not what I claimed. I claimed that it declares a pointer to a
struct containing a BitmapType. There is a big difference. The compiler
*does not need to know* how big that struct is. It just needs to know
how big the pointer is. 

If my code ever declared an instance of "struct _record", *then* the
compiler would need to know the struct size, but I don't ever do
that. Since the struct definition is private, nobody who uses that class
will ever do that either.

In addition, even in the pre SDK4.0r1 days, if I tried to instantiate a
"struct _record" on the stack, my code would have failed, because the
compiler's size calculation of a BitmapType is always wrong, since the
bits of the bitmap actually exist at the end, "outside" of the struct
(ignoring indirect bitmaps, which are not relevant to this discussion).

( ... incorrect code example snipped ... )

> Hope that clears things up a bit...?

No, sorry, but you need to look at my code again, because I'm not doing
what you think I'm doing. I was using a perfectly legitimate technique
that's been broken by Palm's attempt to enforce data abstraction beyond
what C can really provide. I'm not saying that the attempt was a bad
idea, but it will break some legitimate code in the process. However, as
I said before, I can work around that at the expense of making my code a
little less clear (and already have, in fact).

-- 
Dave Carrigan ([EMAIL PROTECTED])            | Yow! When I met th'POPE back in
UNIX-Apache-Perl-Linux-Firewalls-LDAP-C-DNS | '58, I scrubbed him with a MILD
Seattle, WA, USA                            | SOAP or DETERGENT for 15
http://www.rudedog.org/                     | minutes.  He seemed to enjoy
                                            | it..

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to