Re: const Casting
From: Ali R. (nospam_at_company.com)
Date: 11/15/03
- Next message: Gene Wirchenko: "Re: A Certain Size/sizeof"
- Previous message: Ulrich Eckhardt: "Re: A Certain Size/sizeof"
- In reply to: Gene Wirchenko: "Re: const Casting"
- Next in thread: Gene Wirchenko: "Re: const Casting"
- Reply: Gene Wirchenko: "Re: const Casting"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 14 Nov 2003 23:29:58 GMT
"Gene Wirchenko" <gwirchenkoEXCEPT@CAPITALSwencomine.com> wrote in message
news:b8karvsfcmvkkvrev3kshkmov5csand7v9@4ax.com...
> On Fri, 14 Nov 2003 20:43:19 GMT, "Ali R." <nospam@company.com> wrote:
>
> >> void AppendFixed(
> >> std::string & l_b_dest, // IN,OUT: destination buffer
> >> const void * lp_src, // IN: source data pointer
> >> const int & l_s_src // IN: source data length
> >> )
> >>
> >> {
> >> l_b_dest.append(
> >> reinterpret_cast<char *>(const_cast<void *>(lp_src)),l_s_src);
> >
> >append takes a const argument anyway
>
> That adds to my puzzle.
>
I don't understand the puzzle. Append needs a const char *, so you have
to cast your const void * to a const char *.
Pretend that the const weren't there. You would still have to convert
from a void * to a const *.
And it has nothing to do with calling it from the second function.
> >so do this instead
> >
> > l_b_dest.append(reinterpret_cast<const char *>(lp_src),l_s_src);
>
> Yes, but why is my code wrong without the const cast? lp_src
> already is const.
>
> Maybe, this is the crux of the point: Does constness mean that I
> can not cast the data item?
>
> I am trying avoid const casts as I think they are potentially
> very dangerous, at least to my debugging, if not far worse.
> (Reinterpret casts are bad enough.)
>
> [snip]
>
> Sincerely,
>
> Gene Wirchenko
>
- Next message: Gene Wirchenko: "Re: A Certain Size/sizeof"
- Previous message: Ulrich Eckhardt: "Re: A Certain Size/sizeof"
- In reply to: Gene Wirchenko: "Re: const Casting"
- Next in thread: Gene Wirchenko: "Re: const Casting"
- Reply: Gene Wirchenko: "Re: const Casting"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|