C kerdes

vajk fekete halaloszto at yahoo.co.uk
Wed Mar 21 23:38:44 CET 2007


reg volt nekem a C, de hatarozottan ugy emlekszem, hogy a castolas nem egy igazi muvelet, hanem csak a fordito atverese. 

probald ki hogy az (uint)xxx helyett uint temp = xxx es a temp-et hasznalod.

vajk

Fuzesi Arnold <arnold.fuzesi.lista at gmail.com> wrote: A castolas az tudtommal nem az h a memoriabol vesz hozza megegy byte-ot,
ennel bonyibb a dolog.

Mert ha a peldanal maradunk, akkor
az ee_fw.checksum uchar tipusra,  ha ezt mondom:
(uint) ee_fw.checksum akkor az bizony 0x00xx lesz.
Nem a membol veszi ele a byte-okat...

Amit Te mondasz az akkor igaz, ha a szélesebb pointerré kasztolom, es az
erteket veszem:
(( uint*) &ee_fw.checksum)[0]
Ekkor valoban ele(little endian procinal) veszi az ee_fw.cheksum utani 
byte-ot...

Szal tovabbra sem ertem.


Arnold
----- Original Message ----- 
From: "vajk fekete" 
To: 
Sent: Wednesday, March 21, 2007 11:11 PM
Subject: Re: C kerdes


> ha az uint es az uchar merete nem azonos akkor van pityputty.
>
> A castolas az tipuskenyszerites, nem csinal semmit, csak a forditoval
> elhiteti hogy az a tipus.
>
> ha egy byte-ot atcastolok egy word-re, egyszeruen hozzavesz megegy(par)
> byteot mellole a memoriabol.
>
> ha implicit tipuskonverzio tortenik, akkor futasidoben mindent rendesen
> megcsinal. a 01 konvertalva szelesebbre 00000001 lesz.
>
>
> vajk
>
> Fuzesi Arnold  wrote: full optimalizacio,
> eredmenye:
>
> #define EE_CHECKSUM(srcstruct) ee_checksum( ((uchar __eeprom*)
> &srcstruct),
> sizeof(srcstruct)-1)
>
> /******************************************************************************/
> uint ee_checksum(uchar __eeprom* data, uint length)
> {
>    uint checksum = 0;
> do{
>  checksum+=(*data++);
> }
> while(--length);
>    return checksum;
> }
> /******************************************************************************/
>
>
> typedef struct{
>    blabla
>    uchar ee_checksum
> } FW;
>
> volatile __eeprom FW ee_fw;
>
> ez nem mukodik:
>
> if(ee_fw.checksum!=EE_CHECKSUM(ee_fw)){
>        blabla
> }
>
>
> ez mukodik:
> if(ee_fw.checksum!=(uchar)EE_CHECKSUM(ee_fw)){
>    blabla
> }
>
>
> Ezt most hirtelen nem ertem....vki erti?
> Most vagy az ee_fw.checksum-ot kellene castolnia magatol uint-re, vagy az
> ee_checksumot castolni uchar-ra..
>
> A.
>
> -----------------------------------------
>          elektro[-flame|-etc]
>
>
>
> ---------------------------------
> What kind of emailer are you? Find out today - get a free analysis of your
> email personality. Take the quiz at the Yahoo! Mail Championship.
> -----------------------------------------
>          elektro[-flame|-etc]

-----------------------------------------
          elektro[-flame|-etc]


 		
---------------------------------
 Copy addresses and emails from any email account to Yahoo! Mail - quick, easy and free. Do it now...


More information about the Elektro mailing list