(&vec)== &vec[0]?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ioannis Vranos

    (&vec)== &vec[0]?

    C++03:


    Is it always guaranteed that in vector:


    vector<intvec(1 0);

    &vec always points to the first element of the array, for vec.size()0?

  • shaun roe

    #2
    Re: (&amp;vec)== &amp;vec[0]?

    In article <gbtqa8$937$1@u lysses.noc.ntua .gr>,
    Ioannis Vranos <ivranos@no.spa m.nospamfreemai l.grwrote:
    C++03:
    >
    >
    Is it always guaranteed that in vector:
    >
    >
    vector<intvec(1 0);
    >
    &vec always points to the first element of the array, for vec.size()0?
    no

    Comment

    • Pete Becker

      #3
      Re: (&amp;vec)== &amp;vec[0]?

      On 2008-09-30 14:14:32 -0400, Ioannis Vranos
      <ivranos@no.spa m.nospamfreemai l.grsaid:
      C++03:
      >
      >
      Is it always guaranteed that in vector:
      >
      >
      vector<intvec(1 0);
      >
      &vec always points to the first element of the array, for vec.size()0?
      No. In fact, it's almost certainly not true. vector dynamically
      allocates memory for its stored objects, so &vec[0] has no inherent
      relationship to &vec.

      --
      Pete
      Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
      Standard C++ Library Extensions: a Tutorial and Reference
      (www.petebecker.com/tr1book)

      Comment

      • puzzlecracker

        #4
        Re: (&amp;vec)== &amp;vec[0]?

        On Sep 30, 2:56 pm, shaun roe <shaun....@wana doo.frwrote:
        In article <gbtqa8$93...@u lysses.noc.ntua .gr>,
         Ioannis Vranos <ivra...@no.spa m.nospamfreemai l.grwrote:
        >
        C++03:
        >
        Is it always guaranteed that in vector:
        >
        vector<intvec(1 0);
        >
        &vec always points to the first element of the array, for vec.size()0?
        >
        no
        Why not? standard guarantees that.

        Comment

        • Ian Collins

          #5
          Re: (&amp;vec)== &amp;vec[0]?

          puzzlecracker wrote:
          On Sep 30, 2:56 pm, shaun roe <shaun....@wana doo.frwrote:
          >In article <gbtqa8$93...@u lysses.noc.ntua .gr>,
          > Ioannis Vranos <ivra...@no.spa m.nospamfreemai l.grwrote:
          >>
          >>C++03:
          >>Is it always guaranteed that in vector:
          >>vector<intvec (10);
          >>&vec always points to the first element of the array, for vec.size()0?
          >no
          >
          Why not? standard guarantees that.
          &vec is not the same as &vec[0].

          --
          Ian Collins.

          Comment

          • Victor Bazarov

            #6
            Re: (&amp;vec)== &amp;vec[0]?

            puzzlecracker wrote:
            On Sep 30, 2:56 pm, shaun roe <shaun....@wana doo.frwrote:
            >In article <gbtqa8$93...@u lysses.noc.ntua .gr>,
            > Ioannis Vranos <ivra...@no.spa m.nospamfreemai l.grwrote:
            >>
            >>C++03:
            >>Is it always guaranteed that in vector:
            >>vector<intvec (10);
            >>&vec always points to the first element of the array, for vec.size()0?
            >no
            >
            Why not? standard guarantees that.
            Where?

            V
            --
            Please remove capital 'A's when replying by e-mail
            I do not respond to top-posted replies, please don't ask

            Comment

            • puzzlecracker

              #7
              Re: (&amp;vec)== &amp;vec[0]?

              On Sep 30, 3:09 pm, Ian Collins <ian-n...@hotmail.co mwrote:
              puzzlecracker wrote:
              On Sep 30, 2:56 pm, shaun roe <shaun....@wana doo.frwrote:
              In article <gbtqa8$93...@u lysses.noc.ntua .gr>,
               Ioannis Vranos <ivra...@no.spa m.nospamfreemai l.grwrote:
              >
              >C++03:
              >Is it always guaranteed that in vector:
              >vector<intvec( 10);
              >&vec always points to the first element of the array, for vec.size()>0?
              no
              >
              Why not? standard guarantees that.
              >
              &vec is not the same as &vec[0].
              >
              --
              Ian Collins.
              Opps, I misread Pet's comment.

              Comment

              • Juha Nieminen

                #8
                Re: (&amp;vec)== &amp;vec[0]?

                Pete Becker wrote:
                On 2008-09-30 14:14:32 -0400, Ioannis Vranos
                <ivranos@no.spa m.nospamfreemai l.grsaid:
                >
                >C++03:
                >>
                >>
                >Is it always guaranteed that in vector:
                >>
                >>
                >vector<intvec( 10);
                >>
                >&vec always points to the first element of the array, for vec.size()0?
                >
                No. In fact, it's almost certainly not true. vector dynamically
                allocates memory for its stored objects, so &vec[0] has no inherent
                relationship to &vec.
                Since we don't know what "vector" he is talking about (since he didn't
                say he is talking specifically about std::vector), it could
                theoretically be possible for this to be some kind of user-defined
                vector class for which &vec and &vec[0] are the same thing.

                (Yes, just nitpicking.)

                Comment

                • Pete Becker

                  #9
                  Re: (&amp;vec)== &amp;vec[0]?

                  On 2008-10-01 10:27:19 -0400, Juha Nieminen <nospam@thanks. invalidsaid:
                  Pete Becker wrote:
                  >On 2008-09-30 14:14:32 -0400, Ioannis Vranos
                  ><ivranos@no.sp am.nospamfreema il.grsaid:
                  >>
                  >>C++03:
                  >>>
                  >>>
                  >>Is it always guaranteed that in vector:
                  >>>
                  >>>
                  >>vector<intvec (10);
                  >>>
                  >>&vec always points to the first element of the array, for vec.size()0?
                  >>
                  >No. In fact, it's almost certainly not true. vector dynamically
                  >allocates memory for its stored objects, so &vec[0] has no inherent
                  >relationship to &vec.
                  >
                  Since we don't know what "vector" he is talking about (since he didn't
                  say he is talking specifically about std::vector), it could
                  theoretically be possible for this to be some kind of user-defined
                  vector class for which &vec and &vec[0] are the same thing.
                  Sigh. Communication always relies on assumptions. It's always possible
                  to make different assumptions and come to different results. The only
                  issue is whether those other assumptions are reasonable given the
                  context. Since he didn't say what vector he was talking about, it's
                  reasonable to assume that it's std::vector.
                  >
                  (Yes, just nitpicking.)
                  No, just wasting bandwidth playing gotcha.

                  --
                  Pete
                  Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
                  Standard C++ Library Extensions: a Tutorial and Reference
                  (www.petebecker.com/tr1book)

                  Comment

                  Working...