Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #8915

Re: pointer to a pointer problems

From Victor Bazarov <v.bazarov@comcast.invalid>
Newsgroups comp.lang.c++
Subject Re: pointer to a pointer problems
Date 2011-08-16 08:41 -0400
Organization A noiseless patient Spider
Message-ID <j2doh1$lp2$1@dont-email.me> (permalink)
References <ba16570a-e19d-48ad-804f-19cf73bc190d@s2g2000vby.googlegroups.com> <j2bsmi$h54$1@dont-email.me> <c09a411a-a7a4-4968-8d53-c82993a28d6a@1g2000vbu.googlegroups.com>

Show all headers | View raw


On 8/15/2011 4:31 PM, Christopher wrote:
> On Aug 15, 2:40 pm, Victor Bazarov<v.baza...@comcast.invalid>  wrote:
>> In what sense is it unsafe?  You're writing that function.  You can
>> impose any requirements on the data the function receives and introduce
>> all checks necessary...
>
> Perhaps unsafe is the wrong word. Requires more checking and has more
> room
> for error?

Room for error is the reverse side of checking (i.e. when checking is 
lacking), so it can't be "and".  As the programmer of the function, it's 
your responsibility to provide all the checking and thus make it "safe" 
(or "having no room for error").

>> What you get is a pointer to char [by means of its address], right?
>> Supposedly it points to a sequence of characters.  Each character in
>> that sequence has an address, yes?  One of the characters actually
>> starts the "token" you need to find.  The address of that character you
>> will need to return.
>
> That was my original thought, but to really get a "token" back the
> returned pointer must not only point to the address of that character,
> but there must be a '\0' inserted at the end of the token.
>
> Maybe I am misunderstanding the requirements. I can return the address
> of the first character of the token easily, but then the caller is
> going to have to do something useful with it. Probably calculate the
> token length using the original parameter and the returned pointer and
> create their own null terminated string.

You're overthinking it.  Program as requirements state, and for bonus 
points explain what shortfalls you see in the specification.  Since the 
insertion of the null char is not in the requirements, point out to the 
person grading your results that the use of the returning pointer is 
limited if the token is not a true C-string...  And offer your 
alternative solution (based on std::string).

V
-- 
I do not respond to top-posted replies, please don't ask

Back to comp.lang.c++ | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

pointer to a pointer problems Christopher <cpisz@austin.rr.com> - 2011-08-15 11:16 -0700
  Re: pointer to a pointer problems Victor Bazarov <v.bazarov@comcast.invalid> - 2011-08-15 15:40 -0400
    Re: pointer to a pointer problems Christopher <cpisz@austin.rr.com> - 2011-08-15 13:31 -0700
      Re: pointer to a pointer problems Victor Bazarov <v.bazarov@comcast.invalid> - 2011-08-16 08:41 -0400

csiph-web