Re: C++ in ternms of C



In article <uRjypwpRFHA.2604@xxxxxxxxxxxxxxxxxxxx>,
Mark Randall <markyr@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>A class and a structure are effectivly the same in terms of code once
>compiled.
>
>A class has its member variables,
>
>Class A
>{
>public:
> int b, c, d;
>private:
> double e, f;
>};
>
>struct tagA
>{
> int b, c, d;
> double e, f;
>};
>
>
>Each of these is represented in memory as
>
>Class [b][c][d][ e ][ f ]
>Struct [b][c][d][ e ][ f ]

No. tagA is require to be represented as you show (noting that
info on say padding is allowed to be added differently), but
the requirement for A is not constrained to just one the
you showed. For instance, it can also be:

[e][f][b][c][d]

>To consider the other aspects of OOP, we obviously have public, private and
>protected; these are to cause code to be more secure, prevent the fiddling
>by other classes and to impliment a much more powerful and descriptive
>structure to a class. These are of course, completle nonsense to the linker,

Actually, they are allowed to have meaning to the "linker" (whatever
that is), just that they don't in many implementations.

>the compiler performs these checks to tell us that our code conforms to the
>design specification of the class (for example, not changing the member
>variable 'int m_Count' directly when we should have to call the public 'int
>IncrementCount( )'.
>
>You can consider though, when exporting DLL's and functions, the linker will
>utilise these to know which to add to the exports table and which not to.
>
>There is also the consideration of virtual functions, for these the calling
>function needs to know which of the class methods (which in assembly code
>are all accessable anyway) to call, for this we need a special lookup
>table - this is stored elsewhere in the programs data for each individual
>class (not instance of the class).

Right so C++ is allowed to add undeclared members to some classes
in addition to issues of padding, etc.
--
Greg Comeau / Comeau for the Mac? Stay tuned.
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
.



Relevant Pages

  • Re: Size of a structure : Structure Padding
    ... int i1; // 4 ... According to the rules of structure padding shouldn't the size of the ... it shouldn't be 28 bytes for a 32-bit compiler. ... It may very well be that the second member of your structure, ...
    (comp.lang.c)
  • Re: Can nested class members access private members of nesting class?
    ... > then accessed a member of the other. ... List is supposed to be Container. ... "enclose" without being declared a friend, but my compiler doesn't say ...
    (comp.lang.cpp)
  • Re: Variable length arrays proposal
    ... int length; char data;} String; This would indicate to the compiler that the "data" array will have the length indicated by the "length" member. ... The index should be a structure member of integer type. ... Along with the other comments, even if it went through, the index should be size_t, not int. ...
    (comp.std.c)
  • Re: Superbasic efficiency question
    ... > have members such as int a, b, c, d, e or a single member such as int ... perhaps the compiler placed the values in registers. ...
    (comp.lang.c)
  • Re: Superbasic efficiency question
    ... > have members such as int a, b, c, d, e or a single member such as int ... perhaps the compiler placed the values in registers. ...
    (comp.lang.cpp)