структурировать на один байт больше, чем ожидалось - PullRequest
0 голосов
/ 25 июня 2018

У меня есть следующий союз

typedef union {
    uint8_t     bValue;
    uint16_t    uiValue;
    int16_t     iValue;
    uint32_t    ulValue;
    int32_t     lValue;
    struct { // Float messages
        float   fValue;
        uint8_t fPrecision; //Number of decimals when serializing
    };
    struct { //Presentation messages
        uint8_t version;        // Library version
        uint8_t sensorType;     // Sensor type hint for controller, see table above
    };
    char        data[MAX_PAYLOAD + 1];
} mysensor_payload_data;

, и я хочу использовать этот союз в следующем typedef

typedef union {
    struct {

#endif
    uint8_t last;                // 8 bit - Id of last node this message passed
    uint8_t sender;              // 8 bit - Id of sender node (origin)
    uint8_t destination;         // 8 bit - Id of destination node
    uint8_t version_length;      // 2 bit - Protocol version
                                 // 1 bit - Signed flag
                                 // 5 bit - Length of payload
    uint8_t command_ack_payload; // 3 bit - Command type
                                 // 1 bit - Request an ack - Indicator that receiver should send an ack back.
                                 // 1 bit - Is ack messsage - Indicator that this is the actual ack message.
                                 // 3 bit - Payload data type
    uint8_t type;                // 8 bit - Type varies depending on command
    uint8_t sensor;              // 8 bit - Id of sensor that this message concerns.
    // Each message can transfer a payload. We add one extra byte for string
    // terminator \0 to be "printable" this is not transferred OTA
    // This union is used to simplify the construction of the binary data types transferred.
    mysensor_payload_data   payload_data;
};
uint8_t array[HEADER_SIZE + MAX_PAYLOAD + 1];
} /*__attribute__((packed))*/ MyMessage;

сейчас, когда я запускаю следующую строку кода

strncpy(message->payload_data.data, value, length); 

байты записываются в месте 0x20000498, когда «message» находится в 0x2000490.Я бы ожидал, что байт будет в 0x20000497, если я посчитаю правильно.

Почему он пишет в этом месте?

...