0

Maybe a simple question but I have a function that states:

The start address (char* beg) is inclusive, whilst the end address (char* end) is exclusive.

So, lets say I have an array like

double A[N][N];

How do I state the inclusive start and exclusive end, like this?

Start

(char*)A

End

(char*)&A[N][N]

or should I write the end like this.

(char*)&A[N-1][N-1]

Thanks for any help.

2
  • It is quite unusual to pass a 2D array of doubles with char* bounds. Are you sure that your function can handle such a content ?
    – user1196549
    Feb 28, 2014 at 11:10
  • I am trying to pass just the address. Feb 28, 2014 at 11:15

1 Answer 1

1

You start sounds good.
End:
((char*)A) + sizeof(A)

5
  • But doesn't the end of the array A[N][N] have the same memory address as what you have written? Feb 28, 2014 at 11:09
  • The end of the array ends just before this address, this address is one byte after the array, was not that what you were looking for ? Feb 28, 2014 at 11:12
  • If that was exclusive means :) Is it one before or one after. So, that one last byte will contain data from the array too? Feb 28, 2014 at 11:14
  • Do that with a single char: "char a;". The start will be &a. The end will be (&a + sizeof(char)). Here end is the end of the data, exclusive, meaning the data pointed by it is not part of the data. For an array it's exactly the same. Feb 28, 2014 at 11:16
  • I guess it makes no difference in terms of syntax if I make an array on the heap? Feb 28, 2014 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.