-
Anonymous
Неопределенное поведение? Локальная и глобальная область действия и указатель на временный массив
Сообщение
Anonymous »
У меня есть этот исходный код: < /p>
Код: Выделить всё
#include
#include
#include
struct bt_data {
uint8_t type;
uint8_t data_len;
const uint8_t* data;
};
static const char* devName="LSM6DSR_Sensor";
bt_data ad[] = {
{ .type = (0x01), .data_len = (sizeof((uint8_t []) { (0x02 | 0x04) })), .data = (const uint8_t *)(((uint8_t []) { (0x02 | 0x04) })), },
{ .type = (0x09), .data_len = (strlen(devName)-1), .data = (const uint8_t *)(devName), },
};
int main() {
uint8_t d1[] { (0x02 | 0x04) };
bt_data ad3[] = {
{ .type = (0x01), .data_len = 1, .data = d1, },
{ .type = (0x09), .data_len = 14, .data = (const uint8_t *)devName, },
};
bt_data ad2[] = {
{ .type = (0x01), .data_len = (sizeof((uint8_t []) { (0x02 | 0x04) })), .data = (const uint8_t *)(((uint8_t []) { (0x02 | 0x04) })), },
{ .type = (0x09), .data_len = (strlen(devName)-1), .data = (const uint8_t *)(devName), },
};
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79384190/undefined-behaviour-local-vs-global-scope-and-pointer-to-temporary-array[/url]
1737762949
Anonymous
У меня есть этот исходный код: < /p>
[code]#include
#include
#include
struct bt_data {
uint8_t type;
uint8_t data_len;
const uint8_t* data;
};
static const char* devName="LSM6DSR_Sensor";
bt_data ad[] = {
{ .type = (0x01), .data_len = (sizeof((uint8_t []) { (0x02 | 0x04) })), .data = (const uint8_t *)(((uint8_t []) { (0x02 | 0x04) })), },
{ .type = (0x09), .data_len = (strlen(devName)-1), .data = (const uint8_t *)(devName), },
};
int main() {
uint8_t d1[] { (0x02 | 0x04) };
bt_data ad3[] = {
{ .type = (0x01), .data_len = 1, .data = d1, },
{ .type = (0x09), .data_len = 14, .data = (const uint8_t *)devName, },
};
bt_data ad2[] = {
{ .type = (0x01), .data_len = (sizeof((uint8_t []) { (0x02 | 0x04) })), .data = (const uint8_t *)(((uint8_t []) { (0x02 | 0x04) })), },
{ .type = (0x09), .data_len = (strlen(devName)-1), .data = (const uint8_t *)(devName), },
};
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79384190/undefined-behaviour-local-vs-global-scope-and-pointer-to-temporary-array[/url]