Difficulty Understanding C Pointer Syntax -
given following c definitions:
#define sync_byte_1 0x5a #define sync_byte_2 0xa5 and pointer declaration:
uint8 *pcommanddata; pcommanddata = getcommandbufferpointer( lingo_general, stringlength + 3 ); what following 2 lines of code doing pointer?
*pcommanddata++ = sync_byte_1; *pcommanddata++ = sync_byte_2; i don't understand use of * , ++ in instance. if pointer's address being incremented shouldnt * replaced &?
pcommanddata pointer piece of memory. first line
*pcommanddata++ = sync_byte_1; sets value @ address 0x5a, , increments pointer pcommanddata next address. next line
*pcommanddata++ = sync_byte_2; works similarly: sets value pcommanddata points to, 0xa5, , increments pointer next address.
perhaps picture useful. before either line executes, memory in neighborhood of wherever pcommanddata points might this:
| | +--------+ pcommanddata -----> | | +--------+ | | +--------+ | | +--------+ | | after *pcommanddata++ = sync_byte_1;:
| | +--------+ pcommanddata --+ | 0x5a | | +--------+ +--> | | +--------+ | | +--------+ | | and after *pcommanddata++ = sync_byte_2;:
| | +--------+ pcommanddata --+ | 0x5a | | +--------+ | | 0xa5 | | +--------+ +--> | | +--------+ | |
Comments
Post a Comment