Announcement

Collapse
No announcement yet.

C++ to PB help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • C++ to PB help

    Hello,

    I have some C++ code that I am trying to translate to PB code:

    for(i=clear_pos-1,lmask=0XFFF,dshift=12:i>+0X10:I>>=1{
    lmask >>+ 1: /* bit mask for length*?
    dshift__ /* shift width for delta */

    is dshift a C++ built in function?



    ------------------

  • #2
    No. C++ has extremely few built-in operators and functions.

    Just looking at your code fragment, it appears to not be valid C++ code (missing parenthesis, braces, semicolons). Looking more closely at the code, it appears dshift could in fact be a variable. If dshift is a variable, is it possible that what you saw was dshift--? That really means dshift=dshift-1. This would kind of make sense, seeing as this is a loop and in the initializer of the loop dshift is set to 12.


    ------------------




    [This message has been edited by Michael Torrie (edited October 20, 2004).]

    Comment


    • #3
      As Michael says, there are an awful lot of typos in that code. We
      might offer more useful assistance if you could cut'n'paste from
      the original.

      ------------------
      Tom Hanlin, PowerBASIC Staff
      Opinions expressed may not be those of my employer or myself

      Comment


      • #4
        Sorry about that. I see comparing from the original there are some typos.
        This comes from the Sourceforge Linux NTFS project. http://linux-ntfs.sourceforge.net/nt...mpression.html

        for(i=clear_pos-1,lmask=0xFFF,dshift=12;i>=0x10;i>>=1){
        lmask >>= 1; /* bit mask for length */
        dshift--; /* shift width for delta */
        }

        My concern with this for-loop is that Im not sure how to translate
        it into a PB for-loop equivalent. My theory is: If I could better understand
        how the C++ for loop works in this example, I could better understand what
        I need to do in the decompression algorithm.

        Is it possible to break down the loop into individual components for an
        explanation?

        Regards, Tim

        ------------------

        Comment


        • #5
          Although I'm sure someone can translate that (but I think they will need, or you will need to have translated the "dshift" and "lmask" variables/functions first), you may not need to translate that 'verb for verb'.

          What, in context, does that statement do?

          I've seen lots of 'c' code which uses constructs like that to do something simple such as build a powers-of-two or other table used later in the program to mask bits.

          MCM


          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Code:
            for(i=clear_pos-1,lmask=0xFFF,dshift=12;i>=0x10;i>>=1){
                lmask >>= 1; /* bit mask for length */
                dshift--; /* shift width for delta */
            }
            Code:
            i = clear_pos - 1
            lmask = &HFFF
            dshift = 12
            DO WHILE i >= &H10
                SHIFT RIGHT lmask, 1  ' bit mask for length
                DECR dshift           ' shift width for delta
                SHIFT RIGHT i, 1
            LOOP
            ------------------
            Tom Hanlin, PowerBASIC Staff
            Opinions expressed may not be those of my employer or myself

            Comment


            • #7
              Many thanks to all those that replied, and special thanks to Tom for
              translating the C++ to Power Basic.

              I can understand now how the C++ for loop is working.

              Again, Thanks all for your time!

              Tim

              ------------------

              Comment

              Working...
              X