What does this mean?

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

    #1

    What does this mean?



    m_iWidth = (int)pBitmapInf o->bmiHeader.biWi dth;
    m_iHeight = (int)pBitmapInf o->bmiHeader.biHe ight;

    What does this mean?

    I have seen v=&var->member.thing ;

    but what does it mean when you change the & for int?

  • Victor Bazarov

    #2
    Re: What does this mean?

    JoeC wrote:
    m_iWidth = (int)pBitmapInf o->bmiHeader.biWi dth;
    m_iHeight = (int)pBitmapInf o->bmiHeader.biHe ight;
    >
    What does this mean?
    >
    I have seen v=&var->member.thing ;
    >
    but what does it mean when you change the & for int?
    You don't change anythign for anything. The unary operator & is
    for taking the address of the operand. The (blah) notation is
    for *casting* the left operand into a different type. Look it up
    in your favourite C++ book (BTW, which one are you reading that
    doesn't describe those?)

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


    Comment

    • LR

      #3
      Re: What does this mean?

      JoeC wrote:
      >
      m_iWidth = (int)pBitmapInf o->bmiHeader.biWi dth;
      m_iHeight = (int)pBitmapInf o->bmiHeader.biHe ight;
      >
      What does this mean?
      >
      I have seen v=&var->member.thing ;
      >
      but what does it mean when you change the & for int?


      v=&var->member.thing ; means that v is going to get the address of
      var->member.thing .

      &'s precedence is lower than both -and .
      Think of it as:
      v = &(var->member.thing )

      v must be a pointer to whatever type var->member.thing is.

      The change you are asking about wouldn't be all, because the type of v
      would have to change too.

      If this compiles:
      int *v = &var->member.thing ;
      this of course won't:
      int *v = (int)var->member.thing ;
      but this will:
      int v = (int)var->member.thing ;





      LR



      Comment

      • Old Wolf

        #4
        Re: What does this mean?

        On Sep 18, 3:24 pm, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
        JoeC wrote:
        m_iWidth = (int)pBitmapInf o->bmiHeader.biWi dth;
        m_iHeight = (int)pBitmapInf o->bmiHeader.biHe ight;
        >
        The unary operator & is
        for taking the address of the operand. The (blah) notation is
        for *casting* the left operand into a different type.
        The (int) casts what's to the right of it (I'm sure
        you know this, but you wrote 'left operand').

        Also, in this example it casts the entirety of the
        right-hand side of the '=', since -and . bind
        more tightly than the cast.


        Comment

        • Jim Langston

          #5
          Re: What does this mean?

          "JoeC" <enki034@yahoo. comwrote in message
          news:1190080632 .256341.38700@n 39g2000hsh.goog legroups.com...
          >
          m_iWidth = (int)pBitmapInf o->bmiHeader.biWi dth;
          m_iHeight = (int)pBitmapInf o->bmiHeader.biHe ight;
          >
          What does this mean?
          >
          I have seen v=&var->member.thing ;
          >
          but what does it mean when you change the & for int?
          To restate what Victor said,

          (int) is a "c style cast". In C++ we could use that or the safer, prefered
          static_cast<int >.
          & is "address of"
          * is "contents of" (also called dereferencing).

          A cast will convert one type to another. A static cast generally is used to
          covert the value of one type to another. Say, for instance, biWidth was a
          double. The (int) says to convert it to an integer.


          Comment

          • Victor Bazarov

            #6
            Re: What does this mean?

            Old Wolf wrote:
            On Sep 18, 3:24 pm, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
            >JoeC wrote:
            >> m_iWidth = (int)pBitmapInf o->bmiHeader.biWi dth;
            >> m_iHeight = (int)pBitmapInf o->bmiHeader.biHe ight;
            >>
            >The unary operator & is
            >for taking the address of the operand. The (blah) notation is
            >for *casting* the left operand into a different type.
            >
            The (int) casts what's to the right of it (I'm sure
            you know this, but you wrote 'left operand').
            It was a braino, I was thinking that both operators are written
            to the left of what they operate on... Thanks for noticing and
            correcting.
            Also, in this example it casts the entirety of the
            right-hand side of the '=', since -and . bind
            more tightly than the cast.
            I am guesing you use the terms "bind more tightly" in place of
            "have higher precedence".

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


            Comment

            • BobR

              #7
              Re: What does this mean?


              Jim Langston wrote in message...
              "JoeC" wrote in message...

              m_iWidth = (int)pBitmapInf o->bmiHeader.biWi dth;
              m_iHeight = (int)pBitmapInf o->bmiHeader.biHe ight;

              What does this mean?

              I have seen v=&var->member.thing ;

              but what does it mean when you change the & for int?
              >
              To restate what Victor said,
              >
              (int) is a "c style cast". In C++ we could use that or the safer,
              prefered
              static_cast<int >.
              & is "address of"
              * is "contents of" (also called dereferencing).
              >
              A cast will convert one type to another. A static cast generally is used
              to
              covert the value of one type to another. Say, for instance, biWidth was a
              double. The (int) says to convert it to an integer.
              >
              Also:
              // C style cast
              m_iWidth = (int) pBitmapInfo->bmiHeader.biWi dth;

              // C++ style (conversion. watch your compile 'warnings'.)
              m_iWidth = int( pBitmapInfo->bmiHeader.biWi dth );

              --
              Bob R
              POVrookie


              Comment

              • JoeC

                #8
                Re: What does this mean?

                On Sep 17, 10:24 pm, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
                JoeC wrote:
                m_iWidth = (int)pBitmapInf o->bmiHeader.biWi dth;
                m_iHeight = (int)pBitmapInf o->bmiHeader.biHe ight;
                >
                What does this mean?
                >
                I have seen v=&var->member.thing ;
                >
                but what does it mean when you change the & for int?
                >
                You don't change anythign for anything. The unary operator & is
                for taking the address of the operand. The (blah) notation is
                for *casting* the left operand into a different type. Look it up
                in your favourite C++ book (BTW, which one are you reading that
                doesn't describe those?)
                >
                What I mean is that where the (int) is there is a&. That is I can get
                data from a pointer but what does the (int) or the type in () mean?

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

                Comment

                • JoeC

                  #9
                  Re: What does this mean?

                  On Sep 17, 10:55 pm, LR <lr...@superlin k.netwrote:
                  JoeC wrote:
                  >
                  m_iWidth = (int)pBitmapInf o->bmiHeader.biWi dth;
                  m_iHeight = (int)pBitmapInf o->bmiHeader.biHe ight;
                  >
                  What does this mean?
                  >
                  I have seen v=&var->member.thing ;
                  >
                  but what does it mean when you change the & for int?
                  >
                  v=&var->member.thing ; means that v is going to get the address of
                  var->member.thing .
                  >
                  &'s precedence is lower than both -and .
                  Think of it as:
                  v = &(var->member.thing )
                  >
                  v must be a pointer to whatever type var->member.thing is.
                  >
                  The change you are asking about wouldn't be all, because the type of v
                  would have to change too.
                  >
                  If this compiles:
                  int *v = &var->member.thing ;
                  this of course won't:
                  int *v = (int)var->member.thing ;
                  but this will:
                  int v = (int)var->member.thing ;
                  >

                  >
                  LR
                  Thanks, it makes sense now.

                  Comment

                  • BobR

                    #10
                    Re: What does this mean?


                    JoeC wrote in message...
                    On Sep 17, 10:24 pm, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
                    JoeC wrote:
                    m_iWidth = (int)pBitmapInf o->bmiHeader.biWi dth;
                    m_iHeight = (int)pBitmapInf o->bmiHeader.biHe ight;
                    What does this mean?
                    I have seen v=&var->member.thing ;
                    but what does it mean when you change the & for int?
                    You don't change anythign for anything. The unary operator & is
                    for taking the address of the operand. The (blah) notation is
                    for *casting* the left operand into a different type. Look it up
                    in your favourite C++ book (BTW, which one are you reading that
                    doesn't describe those?)
                    What I mean is that where the (int) is there is a&. That is I can get
                    data from a pointer but what does the (int) or the type in () mean?
                    >
                    It's a 'cast'. Remove it and re-compile. Does the compiler complain?

                    --
                    Bob R
                    POVrookie


                    Comment

                    Working...