Re: Efficiency
Michael Kochetkov wrote:[color=blue]
>
> "Pete Becker" <petebecker@acm .org> wrote in message
> news:3F157C91.D 89FAD22@acm.org ...[color=green]
> > Michael Kochetkov wrote:[color=darkred]
> > >
> > > "Pete Becker" <petebecker@acm .org> wrote in message
> > > news:3F154350.D BE527C2@acm.org ...
> > > > Michael Kochetkov wrote:
> > > > >
> > > > > > const char hexdigits [17] = "0123456789ABCD EF" ;
> > > > > A compiler is supposed to copy "0123456789ABCD EF" into hexdigits[/color][/color]
> [17][color=green][color=darkred]
> > > here.
> > > > >
> > > >
> > > > There's no such requirement. In fact this is usually done by direct
> > > > intialization of the array in the executable image, i.e. with no[/color][/color]
> runtime[color=green][color=darkred]
> > > > overhead at all.
> > > I would agree with you, but I am not a compiler or library writer so I[/color][/color]
> am[color=green][color=darkred]
> > > not that self-confident ;).[/color]
> >
> > Please be more careful to distinguish between what the language requires
> > ("a compiler is supposed to ...") and what various compilers do. My main[/color]
> Do not you think your supposed implementation would be broken in case of
> const_cast and recursive functions? I believe the
> literal string and const char s[xxx] are different things and the later
> admits const_cast..[/color]
Of course they're different things. But both are const, and if you cast
away const the behavior of your program is undefined. There is no
conforming program that you can write that can detect whether there the
contents of the string are copied into the array during startup, so
there is no requirement that such a copy take place.
--
"To delight in war is a merit in the soldier,
a dangerous quality in the captain, and a
positive crime in the statesman."
George Santayana
"Bring them on."
George W. Bush
Michael Kochetkov wrote:[color=blue]
>
> "Pete Becker" <petebecker@acm .org> wrote in message
> news:3F157C91.D 89FAD22@acm.org ...[color=green]
> > Michael Kochetkov wrote:[color=darkred]
> > >
> > > "Pete Becker" <petebecker@acm .org> wrote in message
> > > news:3F154350.D BE527C2@acm.org ...
> > > > Michael Kochetkov wrote:
> > > > >
> > > > > > const char hexdigits [17] = "0123456789ABCD EF" ;
> > > > > A compiler is supposed to copy "0123456789ABCD EF" into hexdigits[/color][/color]
> [17][color=green][color=darkred]
> > > here.
> > > > >
> > > >
> > > > There's no such requirement. In fact this is usually done by direct
> > > > intialization of the array in the executable image, i.e. with no[/color][/color]
> runtime[color=green][color=darkred]
> > > > overhead at all.
> > > I would agree with you, but I am not a compiler or library writer so I[/color][/color]
> am[color=green][color=darkred]
> > > not that self-confident ;).[/color]
> >
> > Please be more careful to distinguish between what the language requires
> > ("a compiler is supposed to ...") and what various compilers do. My main[/color]
> Do not you think your supposed implementation would be broken in case of
> const_cast and recursive functions? I believe the
> literal string and const char s[xxx] are different things and the later
> admits const_cast..[/color]
Of course they're different things. But both are const, and if you cast
away const the behavior of your program is undefined. There is no
conforming program that you can write that can detect whether there the
contents of the string are copied into the array during startup, so
there is no requirement that such a copy take place.
--
"To delight in war is a merit in the soldier,
a dangerous quality in the captain, and a
positive crime in the statesman."
George Santayana
"Bring them on."
George W. Bush
Comment