Вопрос

uint8_t * const LCDMem = (uint8_t *) &LCDM3;

This code is used in msp430fg4618 trainer kit for lcd configuration. Could any one please explain the meaning of the above mentioned code?

It allows use of array LCDMem[]? I don't know how.

Это было полезно?

Решение

The operator (type) value is called a cast and implements conversion from one type to another.

The code in your example casts one pointer, the address of LCDM3, to a pointer of a different type. This enables access to the contents of LCDM3 through the LCDMem pointer as if it were a contiguous array of bytes (8-bit unsigned integers).

For example, LDCM3 could be a structure object, or the first element of an array of structures. The above cast would allow one to read and write the individual bytes of the underlying object(s).

Другие советы

LCDMem is not arrray, it is a pointer. This code assigns to LCDMem new address - LCDM3's, so after execution LCDMem will point to LCDM3. Can't say how many bytes allocated for LCDM3, may be array, may be just one.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top