Is C++ a type-safe language ??

S

SaltPeter

Victor Bazarov said:
iostream.h

I think you're confused about what is deprecated. Read that FAQ chapter
carefully. C headers that have the .h form are deprecated. C++ headers
have never had standard form with .h, so they simply cannot be deprecated.
Deprecated means "OK in this edition of the Standard, but may not be OK
later, so don't rely on them".

Better yet, get yourself a copy of the Standard. You will see no mention
of <iostream.h> in it.

V

You've got a point about the use of "deprecated", it doesn't mean
admonished, replaced or removed.
 
R

Richard Herring

SaltPeter said:
NULL isn't defined in the standard,

"C.2.2.3
"The macro NULL, defined in any of <clocale>, <cstddef>, <cstdio>,
<cstlib>, <cstring>, <ctime> or <cwchar>, is an implementation-defined
C++ null pointer constant in this International Standard (18.1)"

18.1.4 says much the same. So its replacement text has to be something
which constitutes a legal C++ null pointer constant.
although rather heavily used and
implied. Example: iterating to past-the-end in an STL container.

How is iterating to past-the end a use of NULL?
A literal string is NOT a pointer.

Did I say it was?
You are referring to a rule that doesn't
apply here.

I'm not.
Its an array of const characters which in the OP's case was used
to initialize a pointer.

"4.2.
"A string literal ... can be converted to an rvalue of type "pointer to
char"... For the purpose of ranking in overload resolution, this
conversion is considered an array-to-pointer conversion followed by a
qualification conversion."
There is a fine line one needs to walk when one
starts saying statements like: "a temporary integer variable therefore
implies a pointer-to-int". Its does not.

Since nobody is saying that, so what? You appear to be arguing against
several things that nobody is saying.
NULL, like any constant is relevent. Here, try to compile this:

#include <iostream>

#define NULL ((void *)0)

int()

Do you mean int main() ?
{
int *p = NULL

Needs a semicolon.
std::cout << p;
}

Note the NULL definition using C's definition (does not compile, not allowed
in C++ to initialize a pointer).

Right, so why are you using a C definition in C++ ?
This solves the issue of why NULL can't and
must not be "assumed".

Not surprisingly, even with the corrections noted, it fails to compile.
*However*, the message _my_ compiler gives is "Redefinition of 'NULL' is
not identical".

If I remove the erroneous definition of NULL, _my_ compiler has no
problems compiling this:

#include <iostream>
int main()
{
int * p = NULL;
std::cout << p;
}

This solves by example the issue of why NULL can't and must not be
"assumed" _not_ to be defined.
c) explained above. ((void *)0) is illegal in C++.

And nobody but yourself has suggested otherwise.

NULL is a null pointer constant. That doesn't mean it's ((void*)0) .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top