Announcement

Collapse
No announcement yet.

Using [ ] notation

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

  • Using [ ] notation

    In the following, the square brackets are used to access the four Bytes that comprise a 32 Bit value.
    Code:
    DIM p AS BYTE Ptr
    ..
    a$ = USING$("#_.#_.#_.#", @p, @p[1], @p[2], @p[3])
    ..
    What is the terminology that describes the square bracket '@p[n]' notation used?

    What I understand, from code samples that I have cut 'n pasted or read in PB's Help:

    The [n] value is an offset from an address. The size of the offset is n*(Sizeof(variable type that p points to)).
    Is that right?

    There are a number of examples that use this notation scattered around in PB's Help topics but I didn't locate an actual description of its use yet.
    Maybe it's just too basic
    Rgds, Dave

  • #2
    Pointers to arrays

    Hi Dave,

    I think the "Pointers to arrays" topic might help.

    Regards,

    Pete.

    Comment


    • #3
      Thank you Peter, that was indeed the topic I should have found!

      "Pointer Indexing" - now I can put a name to it
      Rgds, Dave

      Comment


      • #4
        What is the terminology that describes the square bracket '@p[n]' notation used?
        That's a helpful link Peter, it's called "Pointer Indexing" and each would be called an index pointer.

        And your formula looks correct Dave, eg.
        Code:
        @xPtr[3] = 3     ' same as x%(3)
        assuming xPtr is an INTEGER POINTER set to x%(0)

        Comment


        • #5
          >Maybe it's just too basic

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

          Comment


          • #6
            I think this point raises a very real issue

            If you do not know the 'jargon' on a point you want to look up, where do you start? [Its like using an old fashioned dictionary to check the spelling!]

            I find this extremely infuriating in Microsoft Office. I think that Office has actually defined the jargon - or at least extended its use - and I just do not know where to go. Especially in the formatting aspects.

            What I would like to see is some overall jargon buster paper with screen dumps and little arrows "naming the parts"

            PowerBasic goes someway towards this aim with the Command Summary - but perhaps there are other places where a nice Visio diagram would help people like me who have both the ignorance and the great difficulty that I ofetn get the wrong slant on an explanation for mildly ambiguous statements.

            Maybe this suggestion should go in the PB listens thread.
            [I]I made a coding error once - but fortunately I fixed it before anyone noticed[/I]
            Kerry Farmer

            Comment


            • #7
              pointers

              quite awhile ago i posted some examples of that sort of thing that are fairly short example programs...

              http://www.powerbasic.com/support/pb...light=Pointers
              Fred
              "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

              Comment


              • #8
                Re jargon..... I call the "[]" syntax "pointer offsets;" "()" used with arrays are "subscripts" , not indexes.
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  Originally posted by Dave Biggs View Post
                  What is the terminology that describes the square bracket '@p[n]' notation used?
                  Squindex(es).

                  ===========================================
                  "What do you take me for, an idiot?"
                  General Charles de Gaulle (1890-1970),
                  when a journalist asked him if he was happy
                  ===========================================
                  It's a pretty day. I hope you enjoy it.

                  Gösta

                  JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                  LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                  Comment


                  • #10
                    Thanks guys. I reckon that I feel a lot more comfortable with the use of that (Squindex) notation now.

                    I believe I shall think of it as "Pointer Offset Indexing" such that..

                    The [n] value of each 'Indexed Pointer' is an index to a range of Offset Addresses where..

                    Offset Address = (Base Address) + [n * sizeof(data element)] bearing in mind that..

                    n = 0 TO (Length of Target Data \ Length of Data Element) and that..

                    GPF = [n * Data Elements] > too many
                    Rgds, Dave

                    Comment


                    • #11
                      >>GPF = [n * Data Elements] > too many

                      Actually, it's

                      GPF = [n * (Data Elements-1)] > too many

                      (Pointer offsets are zero-based).
                      Michael Mattias
                      Tal Systems (retired)
                      Port Washington WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment


                      • #12
                        >(Pointer offsets are zero-based).

                        n is zero based..
                        Rgds, Dave

                        Comment

                        Working...
                        X