Results 1 to 9 of 9

Thread: Pointers?

  1. #1
    Join Date
    Aug 2007
    Location
    England
    Posts
    734
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Pointers?

    I get what they do, if im not mistaken they point to the adress at which data is stored, im just wondering what they are useful for? we dont use them in scar? and so im interested in their uses....

    Mat
    The truth finally came out...


  2. #2
    Join Date
    Aug 2006
    Location
    London
    Posts
    2,021
    Mentioned
    2 Post(s)
    Quoted
    0 Post(s)

    Default

    they do point to the address of a variable, and they are useful for a few reasons, heres some

    its much easier to copy the referance than the whole variable, so when you call a method with a string, its faster to pass a pointer-to-string than the whole string, that way you copy only a 32-bit number, instead of a whole array of characters

    also, you can add and subtract pointers, so its a bit better than accessing arrays and places in strings, heres an example
    (btw, i dont know c++ syntax too well.. hopefully it wont show)

    Code:
    int myArray[10];
    int* pointerToArray = &myArray;
    for(int f = 0; f < 10; f++) {
      cout << "index = " << f << " is " << *pointerToArray[0] << endl;
      pointerToArray++;
    }
    its much faster to increment a pointer then go along in the array
    Join the Official SRL IRC channel. Learn how to Here.

  3. #3
    Join Date
    Dec 2006
    Location
    Banville
    Posts
    3,914
    Mentioned
    12 Post(s)
    Quoted
    98 Post(s)

    Default

    Pointers are like... Having WT-Fakawi teaching you SCAR. Yes, they are that awesome.
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

  4. #4
    Join Date
    Aug 2007
    Location
    England
    Posts
    734
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by R0b0t1 View Post
    Pointers are like... Having WT-Fakawi teaching you SCAR. Yes, they are that awesome.
    Useful

    Thanks yakman i see what your getting at with speed, guess itll all fall into place soon thanks
    The truth finally came out...


  5. #5
    Join Date
    Apr 2007
    Posts
    102
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Sorry to be a pain but this the way this has been expressed is potentially confusing.

    A pointer contains an address. This is an address in memory. What is contained at this address could be anything. It could be an integer (or even another address).

    They do NOT point to the address of a variable. They contain an address. When defined as a pointer the compiler will know to treat them as a pointer and know that what they contain is an address and reference the address.

    If a pointer pointed to the address of a variable it would be a pointer to a pointer. (This is possible and is often used but is not what a pointer is). It contains the address - it doesn't point to it. A pointer simply contains an address.

    They are not used in SCAR and SRL because these languages abstract that level of detail away.

    If you wish to know more then I would suggest that you type 'c programming' into Google (or whatever) and see what you can find.

    To start you off try this

    http://www.cs.cf.ac.uk/Dave/C/node10...00000000000000

    btw - hope this is helpful and not confusing (and hope even more that it is correct). Apologies if I have failed in any of these aims

    Paul

  6. #6
    Join Date
    Dec 2006
    Location
    Banville
    Posts
    3,914
    Mentioned
    12 Post(s)
    Quoted
    98 Post(s)

    Default

    Might as well explain offsets while your at it, eh?
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

  7. #7
    Join Date
    Apr 2007
    Posts
    102
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Robot,

    quite happy to explain offsets. But just to be sure I'm answering the correct question, can you explain a little further, maybe with an example what exactly you wish to know.

    Paul

  8. #8
    Join Date
    Aug 2007
    Location
    England
    Posts
    734
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I knew that just didnt explain it properly thanks anyway
    The truth finally came out...


  9. #9
    Join Date
    Apr 2007
    Posts
    102
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Okay Mat, no problem

    It is just that in C and with tricky subject like pointers I have found over the years that it is important to be very precise. Pointers like the opportunity to misbehave if you give them any chance at all.

    Paul

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. c++(pointers) help
    By hackncrack1 in forum C/C++ Help and Tutorials
    Replies: 10
    Last Post: 05-25-2009, 01:38 PM
  2. Method Pointers
    By Grippy in forum OSR Help
    Replies: 9
    Last Post: 03-11-2009, 07:12 AM
  3. My first SRL Script need Pointers
    By Hey321 in forum RS3 Outdated / Broken Scripts
    Replies: 11
    Last Post: 11-12-2006, 07:04 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
  •