Statikus tömb mint struktúra

Hofferek Attila hofi at soka.co.hu
Thu May 18 15:13:14 CEST 2006


Rancz Lajos wrote:
> Üdv!
> 
> Dinamikus memória használat esetén könnyű szép programot csinálni 
> struktúrák használatára:
> 
> tpyedef struct
> {
> 
>     unsigned char a;
>     unsigned int b;
> 
> } strukt1;
> 
> int foo(int)
> {
> 
>     strukt1 *ptr;
>     ptr = malloc(sizeof(strukt1));
>     ptr->a = 5;
> 
> }
> 
> Beágyazott programok esetén ugye nem célszerű mallocot használni, ezért 
> ilyen esetben statikus tömböt kell használni:
> 
> unsigned char arr[512];
> ((strukt1)arr)->a = 5;

strukt1 valami;
memset(&valami,0,sizeof(strukt1));
valami.a=5;
-- 
Hofferek Attila




More information about the Elektro mailing list