Re: Is C++ a type-safe language ??
From: John Harrison (john_andronicus_at_hotmail.com)
Date: 07/06/04
- Next message: Denis Remezov: "Re: Dynamically appending custom data to an object"
- Previous message: Sam Holden: "Re: Is C++ a type-safe language ??"
- In reply to: Nitin Bhardwaj: "Re: Is C++ a type-safe language ??"
- Next in thread: SaltPeter: "Re: Is C++ a type-safe language ??"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 06 Jul 2004 08:18:21 +0100
> Thats what I was pointing out: Here the expression fails because the
> type of 'p' is const char * and 'pc' is char *....so the compiler
> gives 'cannot convert from const char * to char *'. But why doesn't
> give in the following case ?
>
> char *str = "String Literal";
>
> Here also type of "String Literal" is const char * and type of str is
> char * !!
No it isn't, the type of "String Literal" is const char [15], it's an
array not a pointer.
The conversion of this array or const char to char* is explicitly allowed
by 4.2 paragraph 2 of the standard. It's purpose is compatibility with C.
In the very old days C did not have const and so code like your example
was commonplace.
Nevertheless it is an error to use this to modify a string literal.
One excemption from type safety rules for the purpose of bacwards
compatibility does not make C++ a non-type safe language. It is still more
type safe than any other language in common use (AFAIK).
john
- Next message: Denis Remezov: "Re: Dynamically appending custom data to an object"
- Previous message: Sam Holden: "Re: Is C++ a type-safe language ??"
- In reply to: Nitin Bhardwaj: "Re: Is C++ a type-safe language ??"
- Next in thread: SaltPeter: "Re: Is C++ a type-safe language ??"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|