Re: Is C++ a type-safe language ??
In message <5M1Hc.40890$JG 5.871023@news20 .bellglobal.com >, SaltPeter
<SaltPeter@Jupi ter.sys> writes[color=blue]
>
>"Richard Herring" <junk@[127.0.0.1]> wrote in message
>news:iyDAwoH+9 86AFwNm@baesyst ems.com...[color=green]
>> In message <ZADGc.28539$JG 5.587257@news20 .bellglobal.com >, SaltPeter
>> <SaltPeter@Jupi ter.sys> writes[color=darkred]
>> >
>> >"Nitin Bhardwaj" <nitinbhardwaj8 0@hotmail.com> wrote in message
>> >news:17fa8780. 0407052252.2975 67cc@posting.go ogle.com...
>> >> "SaltPeter" <SaltPeter@Jupi ter.sys> wrote in message
>> >news:<LtkFc.19 5935$207.202309 1@news20.bellgl obal.com>...
>> >> > "Nitin Bhardwaj" <nitinbhardwaj8 0@hotmail.com> wrote in message
>> >> > news:17fa8780.0 407012058.3fd2d 5d8@posting.goo gle.com...
>> >> > > Hi all,
>> >> > >
>> >> > > It is said that C++ is a strongly typed language and thus a[/color][/color]
>type-safe[color=green][color=darkred]
>> >> > > language (unlike C). So how does one explain the following[/color][/color]
>behaviour :[color=green][color=darkred]
>> >> > >
>> >> > > int main(void)
>> >> > > {
>> >> > > char *p = NULL;
>> >> > > p = "A String Literal";//the compiler isuues no error/warning[/color][/color]
>here[color=green][color=darkred]
>> >> > > // but ideally it should...as p is a non-const
>> >> > > // pointer and the string literal has the type
>> >> > > // const char *
>> >> > > // So, a conversion from const-ptr TO non-const
>> >> > > // should elicite warning/error from the compiler !!
>> >> >
>> >> > Ideally, what your compiler should do is generate an error about
>> >NULL
>> >> > not being defined.
>> >>
>> >> I had provided a code snippet & not the whole program :-) , Inclusion
>> >> of standard header(s) was assumed.
>> >
>> >No, its not assumed. Your case is the perfect example why. iostream.h is
>> >deprecated and should not be included in any modern code. Basicly,[/color][/color]
>without[color=green][color=darkred]
>> >including the headers, NULL could be anything. Surely, you aren't[/color][/color]
>expecting[color=green][color=darkred]
>> >folks to rely on a crystal ball to substitute values for undefined
>> >constants.[/color]
>>
>> Oh, come off it. NULL is cited all over the place in the Standard, and
>> defined in *seven* different standard headers, any of which could be
>> included by any of the others. You would have to be out of your mind to
>> define it as anything else.[/color]
>
>Wrong, both by fact and principle.[/color]
Sounds grand, but on deeper analysis means little. Which fact above is
wrong? Which principle?
[color=blue]
>The issue is not over where NULL is
>defined[/color]
No. The issue is the type of a string literal, and why the standard
allows conversion of const pointer to non-const pointer in those
circumstances. Your nitpicking over NULL is a digression from the real
point.
[color=blue]
> but rather if NULL is defined.[/color]
.... but if you insist on such nitpicking, the issue is not _if_ NULL is
defined, but _how_ it might be defined, and consequently whether one can
deduce the OP's intention.
[color=blue]
>Read the OP's original quest. His
>code ignores the include directives used in his program. Therefore:
>
>int main()
>{
> char *p = NULL[/color]
If that had merely been
char * p;
the OP's original question would have been substantively identical, and
the answer the same. NULL is an irrelevancet.
[color=blue]
> // ....
>}
>
>can't be compiled. Code posted in the newsgroup should specify the headers
>included.
>
>I strongly disagree with your point of view[/color]
Then you misunderstand it. My point is not that included headers should
be assumed, but that the absence of anything that might be defined - per
the standard - in included standard headers must not be assumed. It's in
the same category as things like defining identifiers with leading
underscores.
[color=blue]
>and the OP's point of view that
>included headers should be assumed.[/color]
[color=blue]
> All of which is rather relevent since it
>turns out he was using iostream.h rather than iostream.[/color]
Hardly. Whichever standard headers he included, there would only be two
possible outcomes:
(a) NULL is undefined
(b) NULL is defined as a null pointer constant.
(c) There is no (c)
Therefore no crystal ball is required to deduce what the OP must have
meant by NULL.
[color=blue]
>That was the whole
>point of the NULL issue.
>[/color]
--
Richard Herring
In message <5M1Hc.40890$JG 5.871023@news20 .bellglobal.com >, SaltPeter
<SaltPeter@Jupi ter.sys> writes[color=blue]
>
>"Richard Herring" <junk@[127.0.0.1]> wrote in message
>news:iyDAwoH+9 86AFwNm@baesyst ems.com...[color=green]
>> In message <ZADGc.28539$JG 5.587257@news20 .bellglobal.com >, SaltPeter
>> <SaltPeter@Jupi ter.sys> writes[color=darkred]
>> >
>> >"Nitin Bhardwaj" <nitinbhardwaj8 0@hotmail.com> wrote in message
>> >news:17fa8780. 0407052252.2975 67cc@posting.go ogle.com...
>> >> "SaltPeter" <SaltPeter@Jupi ter.sys> wrote in message
>> >news:<LtkFc.19 5935$207.202309 1@news20.bellgl obal.com>...
>> >> > "Nitin Bhardwaj" <nitinbhardwaj8 0@hotmail.com> wrote in message
>> >> > news:17fa8780.0 407012058.3fd2d 5d8@posting.goo gle.com...
>> >> > > Hi all,
>> >> > >
>> >> > > It is said that C++ is a strongly typed language and thus a[/color][/color]
>type-safe[color=green][color=darkred]
>> >> > > language (unlike C). So how does one explain the following[/color][/color]
>behaviour :[color=green][color=darkred]
>> >> > >
>> >> > > int main(void)
>> >> > > {
>> >> > > char *p = NULL;
>> >> > > p = "A String Literal";//the compiler isuues no error/warning[/color][/color]
>here[color=green][color=darkred]
>> >> > > // but ideally it should...as p is a non-const
>> >> > > // pointer and the string literal has the type
>> >> > > // const char *
>> >> > > // So, a conversion from const-ptr TO non-const
>> >> > > // should elicite warning/error from the compiler !!
>> >> >
>> >> > Ideally, what your compiler should do is generate an error about
>> >NULL
>> >> > not being defined.
>> >>
>> >> I had provided a code snippet & not the whole program :-) , Inclusion
>> >> of standard header(s) was assumed.
>> >
>> >No, its not assumed. Your case is the perfect example why. iostream.h is
>> >deprecated and should not be included in any modern code. Basicly,[/color][/color]
>without[color=green][color=darkred]
>> >including the headers, NULL could be anything. Surely, you aren't[/color][/color]
>expecting[color=green][color=darkred]
>> >folks to rely on a crystal ball to substitute values for undefined
>> >constants.[/color]
>>
>> Oh, come off it. NULL is cited all over the place in the Standard, and
>> defined in *seven* different standard headers, any of which could be
>> included by any of the others. You would have to be out of your mind to
>> define it as anything else.[/color]
>
>Wrong, both by fact and principle.[/color]
Sounds grand, but on deeper analysis means little. Which fact above is
wrong? Which principle?
[color=blue]
>The issue is not over where NULL is
>defined[/color]
No. The issue is the type of a string literal, and why the standard
allows conversion of const pointer to non-const pointer in those
circumstances. Your nitpicking over NULL is a digression from the real
point.
[color=blue]
> but rather if NULL is defined.[/color]
.... but if you insist on such nitpicking, the issue is not _if_ NULL is
defined, but _how_ it might be defined, and consequently whether one can
deduce the OP's intention.
[color=blue]
>Read the OP's original quest. His
>code ignores the include directives used in his program. Therefore:
>
>int main()
>{
> char *p = NULL[/color]
If that had merely been
char * p;
the OP's original question would have been substantively identical, and
the answer the same. NULL is an irrelevancet.
[color=blue]
> // ....
>}
>
>can't be compiled. Code posted in the newsgroup should specify the headers
>included.
>
>I strongly disagree with your point of view[/color]
Then you misunderstand it. My point is not that included headers should
be assumed, but that the absence of anything that might be defined - per
the standard - in included standard headers must not be assumed. It's in
the same category as things like defining identifiers with leading
underscores.
[color=blue]
>and the OP's point of view that
>included headers should be assumed.[/color]
[color=blue]
> All of which is rather relevent since it
>turns out he was using iostream.h rather than iostream.[/color]
Hardly. Whichever standard headers he included, there would only be two
possible outcomes:
(a) NULL is undefined
(b) NULL is defined as a null pointer constant.
(c) There is no (c)
Therefore no crystal ball is required to deduce what the OP must have
meant by NULL.
[color=blue]
>That was the whole
>point of the NULL issue.
>[/color]
--
Richard Herring
Comment