On Fri, Nov 06, 2015 at 09:24:40PM +0100, Alexander
Huemer wrote:
The relevant expression is:
descr[1].start - load_config
and variations thereof.
descr[1].start is declared include/openbsc/abis_nm.h as:
const uint8_t *start;
simple_config is declared as:
static const uint8_t simple_config[]
So an address is taken and the first element (implicitly) of an uint8
array is substracted from it.
No, not at all :)
simple_config, a uint8_t*, is passed to abis_nm_parse_sw_config. After
that, uint8_t *start is actually pointing at a byte within simple_config.
It's a subtraction of two uint8_t* from each other to get a byte offset:
Subtract simple_config's address (the start of the data) from the "start"
pointer's address value, and the result is a byte offset to get from
simple_config to where "start" is pointing.
The declaration
static const uint8_t simple_config[]
yields a uint8_t*, but declaring it with [] allows initializing a static
array. (Also, simple_config == &simple_config == &simple_config[0], all
uint8_t*, which spaces me out every time I come across it.)
Also note the slight counter intuitiveness of subtracting pointers to get
byte offsets: (T*)a - (T*)b == ((uint)a - (uint)b))/sizeof(T), so this case
gives byte offsets precisely because sizeof(uint8_t) == 1...
Yes, indeed, thanks for the clarification.
So what happens here is pointer arithmetic.
I misinterpreted the right side of the '-'.
Sorry for the noise.
Kind regards,
-Alex