d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Adding Bytes To An Address
Add Reply New Topic New Poll
Member
Posts: 6,562
Joined: Oct 29 2007
Gold: 4.00
Apr 24 2013 05:18pm
For the code below, what are the first 8 addresses accessed?
char- 1 byte, short - 2 bytes, int - 4 bytes, double - 8 bytes

double foo_arr[96]; // starts at address 0x10010000

for (int i = 0; i < 48; i++) {
foo_arr[i] = 8;
}

so the first access will be 0x10010000

then the next access will be 0x10010000 + 8 bytes, right?

I forgot how to do that in hex.
Member
Posts: 6,562
Joined: Oct 29 2007
Gold: 4.00
Apr 24 2013 05:54pm
Ok, disregard that. I remember how to increment the addresses now.

however, in this problem why isn't 0x1001000 simply being incremented by 8 bytes each time?

double foo_arr[80]; // starts at address 0x10010000

for (int i = 0; i < 48; i++) {
foo_arr[i] /= 3;
}

This post was edited by Aimed_Shot on Apr 24 2013 05:54pm
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Apr 24 2013 09:26pm
lets start off with this.

what is happening

and

what do you think should happen. give examples

This post was edited by AbDuCt on Apr 24 2013 09:26pm
Member
Posts: 7,324
Joined: Dec 22 2002
Gold: 1,261.00
Apr 24 2013 09:27pm
What do you mean? What's not being incremented? You don't have a pointer that you are incrementing, foor_arr will always point to 0x1001000 because why wouldn't it? foo_arr[1] WILL resolve to 0x1001008 though, assuming your doubles are 8 bytes.
Member
Posts: 1,158
Joined: Oct 5 2010
Gold: 0.00
May 16 2013 08:02am
Quote (Aimed_Shot @ Apr 25 2013 01:54am)
Ok, disregard that.  I remember how to increment the addresses now.

however, in this problem why isn't 0x1001000 simply being incremented by 8 bytes each time?

double foo_arr[80]; // starts at address 0x10010000

for (int i = 0; i < 48; i++) {
    foo_arr[i] /= 3;
}



a += b; increments the value.
a |= b; is a logical or which results in something along the lines of : 0x0001 + 0x0100 = 0x0101
a &= ~b; disables b in a, or as example: 0x1010 - 0x1000 = 0x0010

Not sure what you mean with /= - never used that one, but i think you're trying to simply do a += ?

What "are" you trying to do?
Member
Posts: 312
Joined: May 5 2010
Gold: 1.20
Warn: 40%
May 26 2013 06:40pm
Can't you just realloc() 'x' bytes?
Member
Posts: 4,605
Joined: Sep 15 2011
Gold: 9,464.00
May 27 2013 05:21pm
why is this thread resurrected
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll