Here is a piece of code. It is not clear what is being done in cycles. Not even the syntax itself is clear.

typedef struct { uint8_t dst; uint8_t regnum; uint8_t len; uint8_t *data; uint8_t checksum; } __attribute__((__packed__)) pkt_t; for (i = 0; i < 3; i++) pkt.checksum += ((uint8_t *)&pkt)[i]; for (i = 0; i < len; i++) pkt.checksum += ((uint8_t *)data)[i]; 

    1 answer 1

    In the first cycle, the checksum structure is assigned the value of the sum of the values ​​of the first three bytes that make up the pkt structure. In the second cycle, the sum of the len bytes of the array of variables uint8_t, indicated by the data field, is added to this value of the specified field.

    • I will add only that numbers without a sign of 1 byte (0-255) in size are added - avp
    • Exactly. Speaking in terms of processor instructions, unsigned addition is performed. - skegg
    • Thank you for the answer) - Johnny_Stray
    • @mikillskegg clarify, so clarify. The first three bytes of pkt are dst, regnum, len. - alexlz
    • @alexiz, I think the author of the question will figure it out himself. - skegg