Results 1 to 4 of 4

Thread: C to VB

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    C to VB

    I have this C statement:

    Code:
    *pcm = *--(pste + 1)->pcmFirst;
    pcm is a pointer to a structure array element called argcm

    pste is a pointer to a structure array element called argste

    pcmFirst is a member of argste which is a pointer to the first array element of argcm that is used by this array element of argste

    From what I have been told the above C statement works like this:

    1) increment the argste pointer (pste) by 1 so that it temporarly points to the next argste element

    2) get the value of it's pcmFirst pointer and decrement it by 1 and replace the current address with this new address

    3) using this new address copy the data from this array cell to the cell pointed to by pcm

    4) put the new address in the argste cell's pcmFirst member

    Below is what I think is the correct VB translation but I am not 100% sure:

    Note:
    Where you see pcm in the above C code I use pcm_indx in my VB code. The C code pcm is a pointer to the physical address of the array element and in my VB pcm_indx is an index to the same array element. Same thing for the C pste I use pste_indx.

    In the C code pcmFirst contains an address to a argcm array element but in my VB code pcmFirst contains an index to the same array element

    Code:
    'Step 1 and 2
    argste(pste_indx + 1).pcmFirst = argste(pste_indx + 1).pcmFirst - 1
    
    'Step 3
    argcm(pcm_indx).binit = argcm(argste(pste_indx + 1).pcmFirst).binit
    argcm(pcm_indx).cmf = argcm(argste(pste_indx + 1).pcmFirst).cmf
    argcm(pcm_indx).cmk = argcm(argste(pste_indx + 1).pcmFirst).cmk
    argcm(pcm_indx).isqFrom = argcm(argste(pste_indx + 1).pcmFirst).isqFrom
    argcm(pcm_indx).isqTo = argcm(argste(pste_indx + 1).pcmFirst).isqTo
    
    'Step 4
    argste(argste(pste_indx + 1).pcmFirst).pcmFirst = argste(pste_indx + 1).pcmFirst
    Can someone who knows both C and VB tell me if my VB code is correct
    Last edited by jmsrickland; Feb 25th, 2015 at 11:34 AM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    2,238

    Re: C to VB

    Not sure about this one:
    Code:
    'Step 1 and 2
    argste(pste_indx + 1).pcmFirst = argste(pste_indx + 1).pcmFirst - 1
    Since a pointer is a 32-bit integer (a Long) i would have expected
    Code:
    argste(pste_indx + 1).pcmFirst = argste(pste_indx + 1).pcmFirst - 4
    But i admit i'm not sure i even understand this. Pointer-Arithmacy was never my forte
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: C to VB

    C uses pointers to structures so in the C code pcm and pste are the pointers but in VB I am not using pointers but rather indexes into the structures. So when a C pointer like pcm points to the physical address if an array element of the structure then my pcm_indx is the index to the same array element

    I have edited my original post to indicate this


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  4. #4
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,119

    Re: C to VB

    Quote Originally Posted by jmsrickland View Post
    ...
    Note:
    Where you see pcm in the above C code I use pcm_indx in my VB code. The C code pcm is a pointer to the physical address of the array element and in my VB pcm_indx is an index to the same array element. Same thing for the C pste I use pste_indx.
    Code:
    'Step 1 and 2
    argste(pste_indx + 1).pcmFirst = argste(pste_indx + 1).pcmFirst - 1
    
    'Step 3
    argcm(pcm_indx).binit = argcm(argste(pste_indx + 1).pcmFirst).binit
    argcm(pcm_indx).cmf = argcm(argste(pste_indx + 1).pcmFirst).cmf
    argcm(pcm_indx).cmk = argcm(argste(pste_indx + 1).pcmFirst).cmk
    argcm(pcm_indx).isqFrom = argcm(argste(pste_indx + 1).pcmFirst).isqFrom
    argcm(pcm_indx).isqTo = argcm(argste(pste_indx + 1).pcmFirst).isqTo
    
    'Step 4
    argste(argste(pste_indx + 1).pcmFirst).pcmFirst = argste(pste_indx + 1).pcmFirst
    Can someone who knows both C and VB tell me if my VB code is correct
    I don't see the reason for step 4. You are indexing a ste array by a cm array index, which would really screw things up I would think.
    And couldn't step 3 be a simple User Defined Type (UDT) to UDT assignment.

    The purpose of the of the C code is to remove generated moves for an iteration that leave your King in check.
    The generated moves for a given iteration are identified by two pointers (aka indexes) into the argcm array.
    argste(pste_indx).pcmFirst points to the first move of the series.
    argste(pste_indx+1).pcmFirst points to where the first move of the next series will start, so is pointing to the element just beyond the current series of moves.
    That is why you are comparing your index against the (argste(pste_indx+1).pcmFirst value to see when the loop index goes past your current list of moves.

    As you iterate through the array, if you find a move that leaves the King in check you want to remove that move.
    The code "removes" the move, by moving the last move in your series into that spot (and doesn't increment the pointer so that you test the move moved into that slot the next iteration).

    So, assume you have 20 moves in your series, which start at array position 10 and end at 29.
    That would mean argste(pste_indx).pcmFirst would be 10, and argste(pste_indx + 1).pcmFirst would be 30, delineating your range of moves.
    You set pcm_indx to 10, and check to see if move 10 leaves your King in check.
    Let's say you get to pcm_indx = 15, and that move puts the King in check.
    You don't want that move, so you want to copy your last move (at 29) to this slot.

    So, you decrement argste(pste_indx + 1).pcmFirst, taking it from 30 to 29. (the next series will now begin at 29 instead of 30).
    You copy the structure from 29 to 15.
    You don't increment pcm_indx so is stays at 15.
    When you loop around, you will check 15 again (which is now the former move 29) to see if it will leave your King in check.
    You continue in like manner until pcm_indx >= argste(pste_indx + 1).pcmFirst.

    So, as I see it, that one line of C code should only be two lines of VB.
    argste(pste_indx + 1).pcmFirst = argste(pste_indx + 1).pcmFirst - 1 'decrement the start of next series pointer
    argcm(pcm_indx) = argcm(argste(pste_indx + 1).pcmFirst) 'copy the last move to the current position.
    Last edited by passel; Feb 25th, 2015 at 03:03 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width