Page 2 of 2 FirstFirst 1 2
Results 21 to 35 of 35

Thread: Data Structures     submit to reddit submit to twitter

  1. #21
    New Merits
    Join Date
    Feb 2006
    Posts
    241
    BG Level
    4

    Quote Originally Posted by Zhais View Post
    but pointer havoc is so fun!

    I remember this stuff fairly well, because I thought it was so damned nifty when I learned it. Let me figure out how iterators worked before I knew what iterators were.
    Ever done bit masking? Easy once you get it but OH MY FUCKING GOD figuring it out the first time is a nightmare. Kinda makes me sad that it's nearly impossible to do anymore with java.

  2. #22
    E. Body
    Join Date
    Sep 2007
    Posts
    2,019
    BG Level
    7
    FFXI Server
    Fenrir

    Need moar posts like this ^^

  3. #23
    Bagel
    Join Date
    Jan 2006
    Posts
    1,428
    BG Level
    6

    Quote Originally Posted by shieldsofwindurst View Post
    Ever done bit masking? Easy once you get it but OH MY FUCKING GOD figuring it out the first time is a nightmare. Kinda makes me sad that it's nearly impossible to do anymore with java.
    Yea, I've been messing with that a bit during game programming. I've been trying to use more parameters as bitwise-& flags rather than separate bool values. Does java natively not let you do bitwise | and &? I can still do them fine in C#.

  4. #24
    ilduce
    Guest

    Here's what going on in your first program, I'll annotate your code:

    #include <stdio.h>
    int main (void)
    {
    int a[5] = {5,4,3,2,1}; //a is not an int array that holds five int values
    //for instance lets say the address of a[0] is 0x50


    int i = 2; //an int called i is assigned a value of 2
    int *p = &a[2]; //now you are declaring a pointer to the THIRD element
    //(remember 0 based arrays in c) the third element has an address of 0x58
    //notice the EIGHT on the end, why is this? because the size of an int
    //is such that the elements in the int array have the address 0x50, 0x54,
    //0x58, 0x5c, 0x60


    printf("%d %d", *(a+i), p[3]); // now you're printing out *(a+1) which is a[2] which is 3
    // then you try to print out p[3] which in reality is like saying a[5], because you already assigned p to //point to the THIRD element in the array called 'a', if on the other hand you would have said p[2] you //would have gotten 1 but you said p[3] which is going to give you a random memory address
    system("pause");
    }

    Those numbers in the array make it very hard for a student to understand because arrays are zero based, bad example on the teachers part.

  5. #25
    New Merits
    Join Date
    Feb 2006
    Posts
    241
    BG Level
    4

    Quote Originally Posted by nitsuj View Post
    Need moar posts like this ^^
    I once lost an entire fucking day debugging about 128 individually masked bits coming in off a hardware board in Ada. Turned out the masking actually worked correctly, but the ass-backwards way the constants were coded and the complete lack of documentation forced me to redo it completely just so anyone who hadn't seen it before could have a PRAYER of figuring it out in less than 6 hours.

  6. #26
    Bagel
    Join Date
    Jan 2006
    Posts
    1,428
    BG Level
    6

    Also, thank you guys for giving me something to focus on other than my tech writing assignment... god I hate this class ~.~

  7. #27
    Bagel
    Join Date
    Jan 2006
    Posts
    1,428
    BG Level
    6

    Quote Originally Posted by shieldsofwindurst View Post
    I once lost an entire fucking day debugging about 128 individually masked bits coming in off a hardware board in Ada. Turned out the masking actually worked correctly, but the ass-backwards way the constants were coded and the complete lack of documentation forced me to redo it completely just so anyone who hadn't seen it before could have a PRAYER of figuring it out in less than 6 hours.
    .... seriously, 128 individual constants with no documentation?

    Oi my head.

  8. #28
    New Merits
    Join Date
    Feb 2006
    Posts
    241
    BG Level
    4

    Quote Originally Posted by Zhais View Post
    Yea, I've been messing with that a bit during game programming. I've been trying to use more parameters as bitwise-& flags rather than separate bool values. Does java natively not let you do bitwise | and &? I can still do them fine in C#.
    It's not that you can't do the bitwise operations, its that it's near impossible (or it was, last time I tried) to break down a java object into bit-sized chunks so that you Can mask 8 or however many bits for an interface. Of course, that was like 2-3 years ago, so a new jdk probably added in support for that. But in the early days of java it was a nightmare, like doing a freaking hello world program. First hello world program I ever wrote that took like 500 lines.

  9. #29
    Bagel
    Join Date
    Jan 2006
    Posts
    1,428
    BG Level
    6

    Quote Originally Posted by shieldsofwindurst View Post
    It's not that you can't do the bitwise operations, its that it's near impossible (or it was, last time I tried) to break down a java object into bit-sized chunks so that you Can mask 8 or however many bits for an interface. Of course, that was like 2-3 years ago, so a new jdk probably added in support for that. But in the early days of java it was a nightmare, like doing a freaking hello world program. First hello world program I ever wrote that took like 500 lines.
    If I'm thinking of it right, C# way of doing that would be somewhat like this...

    Code:
    int mask1 = 0x11111111; //Rightmost 8 bit mask
    int mask2 = 0x1111111100000000; //Next set of 8
    int mask3 = 0x111111110000000000000000; //Next set of 8
    ints wouldn't be big enough, ugly and can just use proper numerical value, but you get the point. That is probably a bassackwards way of going about it as well.... I need to look into it more!

    Probably something with the << operator as well. ( bigMask & (smallMask << (8*maskNum))) maybe?


    I prefer not to ever mess with hardware like this, so I've never personally studied it. I much prefer to just make high-end applications. So much easier and can have fun with it.

  10. #30
    New Merits
    Join Date
    Feb 2006
    Posts
    241
    BG Level
    4

    Quote Originally Posted by Zhais View Post
    If I'm thinking of it right, C# way of doing that would be somewhat like this...

    Code:
    int mask1 = 0x11111111; //Rightmost 8 bit mask
    int mask2 = 0x1111111100000000; //Next set of 8
    int mask3 = 0x111111110000000000000000; //Next set of 8
    ints wouldn't be big enough, ugly and can just use proper numerical value, but you get the point. That is probably a bassackwards way of going about it as well.... I need to look into it more!

    Probably something with the << operator as well. ( bigMask & (smallMask << (8*maskNum))) maybe?


    I prefer not to ever mess with hardware like this, so I've never personally studied it. I much prefer to just make high-end applications. So much easier and can have fun with it.
    That's pretty much it, though obviously it's easier to maintain if you do like


    int mask1 = 0b000000000000000011111111; //Rightmost 8 bit mask
    int mask2 = 0b000000001111111100000000; //Next set of 8
    int mask3 = 0b111111110000000000000000; //Next set of 8

    etc etc...

    Of course when you're dealing with lots of them then you don't make really big numbers, you just read them all into a data structure containing multiple ints or bytes or whatever which you mask individually. Easy to do in C with structs; not sure the best way to do it in C++ and later. I only really did that sort of thing in Ada & C so I can't really speak to it in newer languages.

  11. #31
    Ive sucked 27 dicks, in a row.
    Join Date
    Apr 2006
    Posts
    1,569
    BG Level
    6

    Late, but pointer arithmetic does actually take into account the size of the type being pointed to. That's why we have typed pointers - if you have an int* on an architecture with 32-bit ints, the compiler knows that incrementing that pointer should actually increase it by 4 bytes, not 1. If you actually want to increment a pointer by physical bytes rather than logical units, you have to cast the pointer to a single-byte pointer type.

  12. #32
    netz
    Guest

    Quote Originally Posted by Zosi View Post
    Late, but pointer arithmetic does actually take into account the size of the type being pointed to. That's why we have typed pointers - if you have an int* on an architecture with 32-bit ints, the compiler knows that incrementing that pointer should actually increase it by 4 bytes, not 1. If you actually want to increment a pointer by physical bytes rather than logical units, you have to cast the pointer to a single-byte pointer type.
    As an aside, beware opening gdb to debug your program and trying to print the value of *(&a+2) ... gdb will take the memory address of a, add two bytes, and print whatever is there, which may not be what you want.

    Quote Originally Posted by shieldsofwindurst View Post
    It's not that you can't do the bitwise operations, its that it's near impossible (or it was, last time I tried) to break down a java object into bit-sized chunks so that you Can mask 8 or however many bits for an interface. Of course, that was like 2-3 years ago, so a new jdk probably added in support for that. But in the early days of java it was a nightmare, like doing a freaking hello world program. First hello world program I ever wrote that took like 500 lines.
    Java land wants you to use EnumSets instead, which internally are bit fields.

  13. #33
    /lick
    Join Date
    Sep 2005
    Posts
    1,226
    BG Level
    6
    FFXIV Character
    Srs Bsns
    FFXIV Server
    Excalibur
    FFXI Server
    Asura

    And this right here is why my CS degree is a placemat and I chose to pursue an engineering role in field sales for a tech company.

    Problem solving is fun. Debugging pointers is not.

    I'm actually a little surprised I remember how everything works (been about 3 years since I've touched C), but I'd kill myself if I had to code day in and day out.

  14. #34
    Bagel
    Join Date
    Jan 2006
    Posts
    1,428
    BG Level
    6

    You can be a programmer without dealing with pointers Plenty of high-level languages out there

  15. #35
    E. Body
    Join Date
    Jan 2007
    Posts
    2,103
    BG Level
    7

    Quote Originally Posted by Amastacia View Post
    but I'd kill myself if I had to code day in and day out.
    Eh, I guess it depends what you're actually coding for. If you're coding for a field you aren't interested in, you probably won't enjoy it. At least, this is how it is for me; once I graduate I'll have a little more flexibility with who and what I'm coding for.

Page 2 of 2 FirstFirst 1 2

Similar Threads

  1. Cached data
    By Not Kuno in forum General Discussion
    Replies: 7
    Last Post: 2006-10-25, 18:49
  2. Jilted woman deletes ex's online RPG data
    By Sadler in forum General Discussion
    Replies: 8
    Last Post: 2005-01-31, 02:53