Re: The C++ type system
On Jan 9, 7:15 pm, "Paul" <pchris...@yahoo.co.uk> wrote:
"Francis Glassborow" <francis.glassbo...@btinternet.com> wrote in message
news:QY-dnbKcU4ySJ7XQnZ2dnUVZ8kWdnZ2d@bt.com...
The C++ type system can is far from simple and the
terminology for writing about it can be confusing so I will
no doubt fail in the eyes of at least one person to be
entirely correct in the following. C++ types include:
1) Object types
Fundamental types
Derived types (that is types that are derived from other types by adding
cv qualifiers)
Enum types
Class types
A class is not a type, a class defines a UserDefinedType.
A class definition defines a type. Types defined by class
definitions are called class types, to distiguish them from e.g.
fundamental types, enum types, etc.
[...]
Pointer types
A pointer is NOT a type.
No. A pointer is an object (in C++) which has pointer type.
A pointer is a varaible that has a type of integer(or some
similar type, that is capable of storing an address) .
A pointer most definitly doesn't have an integral types. A
pointer has pointer type.
Array types
Collectively the above types are called object types
2) Function types
Function types (divided into free functions and member
functions). Member functions come in two flavours, static
member functions that provide the behaviour for the class as
a whole and non-static member functions that provide the
behaviour for individual instances (objects) of the class.
Function types are not object types (by explicit statement
in the C++ Standard) however it is possible to derive a
pointer to (possibly member) function and these are object
types. All pointer types, AFAIK but I am happy to be
corrected on this issue -- are object types.
A function is not a type
But a function has a type. A function type is not an object
type, because a function is not an object.
3) Reference types
Reference types are easily misunderstood because in the context of C++
they are not the same as reference types in other languages (such as
Java). Effectively a reference (and instance of a reference type) provides
another handle for an existing type. Every non-reference type in C++ has
an associated reference type. Nothing can be derived from a reference
type. You cannot cv qualify a reference type, you cannot have an array of
a reference type and you cannot have a pointer to a reference type.
A referene is not a type anymore than a pointer is a type.
A reference is not a type; a reference is an entity, which has a
reference type.
A reference is simply an alias.
It none the less has a type.
Do you know what "type" means in a programming language context?
Note on static v dynamic type
All entities have a static type which is the type with which they are
declared. In the case of pointers and references there is a second
(dynamic) type which is the type of the entity actually pointed to (well
strictly speaking it is the type of the pointer to that type) or
referenced. C++ provides a mechanism to access the behaviour of the
dynamic type when that is different to the behaviour of the static type.
The above is the scribblings of a very confused C programmer.
No. The above describes rather exactly how the type system
works in C++.
What is a C++ object?
The Standard dictates that an object is a region of storage coupled with
an object type. Note that neither functions nor references are objects but
storage for a pointer is. [Another confusion is that we loosely refer to a
pointer to mean both the value (an address in colloquial terminology) and
the storage for such a value.]
Again the scribblings of a very confused C programmer.
No. The above describes rather exactly the object model in C++.
Objects of a user defined type can be composed of sub-objects. In the
interests of efficiency some license is granted to sub-objects that is not
available to complete objects. A sub-object can be of zero size and a
sub-object can occupy disjoint storage (the latter is essential in order
to support C++ multiple inheritance). In addition to sub-objects all
object types (including built-in types) allow the inclusion of other
storage which is either padding or used for internal purposes.
A licence is granted to subobject? :S
WTF is that shit?..... is the subobject going to be selling tobacoo and
alcohol
If you don't want to understand, then there's not much we can do
to help you.
[...]
A pointer is generally NOT thought of as a TYPE in programming, it's a
pointer to an address.
What you just said doesn't make sense in English.
Technically speaking when you examine a pointers TYPE it's some kind of
INTEGER TYPE, suitable for the memory addressing system.
And that's simply not true in any language I know (except maybe
assembler, and very early C). A pointer does *not* have an
integral type; it has a pointer type.
IF you think a pointer should be described as a TYPE in the
context of the C++ standards... IDGAF but it just poves what
an asshole you are.
He never said that a pointer was a type. He said that in C++,
there are pointer types. It would help if you could read.
To post this bullshit in a beginners forum in a deliberate
attempt to mislead and confuse people,
Now that's something that would apply to your own postings.
--
James Kanze