[elektro] C - memset

Kiss Gabor kissg at ssg.ki.iif.hu
Wed Feb 3 17:34:13 CET 2016


On 02/03/2016 05:28 PM, uprogc . wrote:
> /* A struktúrám típusa: */
> typedef struct{
>    uint32_t tag32;
>    uint8_t tag8_1;
>    uint8_t tag8_2;
> } __attribute__((packed)) TEST_t;
> 
> /* A kód: */
> int main(void){
> TEST_t test;
> uint8_t len;
> 
>    len = sizeof(TEST_t);        /* 6 byte lett a pakolás után */
> 
>    memset(&test, 0, 6);

El nem tudom képzelni, hogy a _struktúra_ elsõ byte-ja ne legyen
kinullázva.
Hogy mérted ki?

>>> Ha memset() eseten a struktura meretet sizeof(tipus)-al megadom, akkor
>>> rendben van, ha viszont konstans 6 ertekkel adom meg a meretet, akkor az
>>> elso byteot nem allitja be a memset :)

kissg
-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?



More information about the Elektro mailing list