Thread: Does this even remotely make sense

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    7

    Exclamation Does this even remotely make sense

    I have encountered a very very strange situation in this
    Code:
    //patches is a **ptr
    tmp_ptr=patches[0]+9; //when i printf'ed this it said 0x3F0072
    
    tmp_ptr=patches[0]; //when i printf'ed this it said 0x3F002A
    //actually this last one is the correct one
    now can anyone come up with an explanation for why this happens

    I am using mingw btw

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Why what happens? that you print out a memory address.
    Woop?

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Or do you mean why the +9 moves the address forwards 0x48 bytes?
    Well that's pointer arithmetic for you - it looks like whatever is being pointed to is 8 bytes in size.

    It's no use telling us something is a **variable without stating the type.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Well that's pointer arithmetic for you - it looks like whatever is being pointed to is 8 bytes in size.
    A double, maybe?

    Is that the output you expected? Maybe you want to print **variable and not variable.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Dec 2005
    Posts
    7
    thank you so much for pointing that out for me
    it is actually of type patch_entry which is a struct(8byte)

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Did you figure out what you wanted to figure out?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Registered User
    Join Date
    Dec 2005
    Posts
    7
    yes
    i was thinking the +9 would mean +9 bytes not patch_entry structs

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Win32 Common Controls in C++, how do i make and use them?
    By C+noob in forum Windows Programming
    Replies: 6
    Last Post: 01-09-2006, 11:53 AM
  2. want to make this small program...
    By psycho88 in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2005, 02:05 AM
  3. make all rule
    By duffy in forum C Programming
    Replies: 9
    Last Post: 09-11-2003, 01:05 PM
  4. Question about atheists
    By gcn_zelda in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 08-11-2003, 11:50 AM
  5. 'functions' in make?
    By mart_man00 in forum C Programming
    Replies: 1
    Last Post: 06-21-2003, 02:16 PM