kerdesek
hoyuka hoya
hoyuka at c2.hu
Thu Sep 1 12:52:27 CEST 2005
Hali,
Ha char* data;-t irsz, akkor az nem jo. Mast jelent. Nem ertem mi a baj a
char data[0]-val. Nem eszi meg a fordito? Milyen fordito az? Esetleg
megrpobalhatnad char data[1]-el, hatha senki se csinal 0 mereto
package-et.
Vagy ha nem nagy a forras, akkor csinalhatnal egy ilyen workaround-ot:
typedef struct Lofasz {
int size;
} Lofasz;
inline Lofasz * Lofasz_alloc(int size) {
return (Lofasz*)malloc(sizeof(Lofasz)+size*sizeof(char));
}
inline char * Lofasz_getData(Lofasz *lofasz) {
return (char*)lofasz+sizeof(Lofasz);
}
int main() {
//ezek utan structura letrehozasa:
Lofasz *lofasz=Lofasz_alloc(1024);
// cimzese:
char *data=Lofasz_getData(lofasz);
data[0]=3;
data[1]=2;
data[2]=1;
data[3]=0;
// felszabaditas:
free(lofasz);
}
udv.
hoyuka
Valenta Ferenc said:
> hoyuka hoya wrote:
>
>> typedef struct Lofasz {
>> int size;
>> char data[0];
>> };
>>
>> Ezek utan egy Lofasz strukturat, amibe 1024 byte-ot lehet belepakolni,
>> igy
>> lehet letrehozni:
>
> Ertem, csak nem igy csinaltam volna, mert ez nem mukodik.
> Az a kerdes, hogy ha a fenti peldaban a char data[0] helyett
> char *data-t irok, akkor az jo, de 100% ugyanaz mint a data[0]?
> Koszi mindenkinek az eddigi segitseget!
>
> --
> Valenta Ferenc <ferenc.valenta at vhl.hu> Volcano/Mentor Graphics
> "My love is REAL, unless declared INTEGER"
>
>
> -----------------------------------
> Szponzorunk: http://tonerbolt.hu/
>
-------------------------------------
Mi a C2? http://mail.c2.hu
More information about the Elektro
mailing list