Cos'è ElectroYou | Login Iscriviti

ElectroYou - la comunità dei professionisti del mondo elettrico

64 bits cast in C99

Linguaggi e sistemi

Moderatori: Foto UtentePaolino, Foto Utentefairyvilje

0
voti

[11] Re: 64 bits cast in C99

Messaggioda Foto UtenteShockwaver » 22 mag 2014, 20:46

Esatto!
Ed è proprio da lì che ho estrapolato quella dichiarazione, infatti nelle librerie del compilatore che sto utilizzando si trova questo:
Codice: Seleziona tutto
typedef   unsigned long long int __uint64_t;

#ifndef   uint64_t
typedef   __uint64_t   uint64_t;
#define   uint64_t   __uint64_t
#endif


Grazie ancora ad entrambi.
Anyone who has never made a mistake has never tried anything new
Two things are infinite: universe and human stupidity, and I'm not sure about the former
You did not really understand something unless you can explain it to your grandmother
A. Einstein
Avatar utente
Foto UtenteShockwaver
770 1 5 11
Expert
Expert
 
Messaggi: 859
Iscritto il: 3 mar 2010, 18:56

0
voti

[12] Re: 64 bits cast in C99

Messaggioda Foto UtenteShockwaver » 22 mag 2014, 21:28

Allora, da premettere che per lapsus ho detto che i PIC32 gestiscono i byte in big-endian, in realtà lo fanno in little-endian... ma il punto è che mi sono perso..
L'unico problema di "allineamento" che vedo è quello legato all'endianness dell'architettura.
Se riempo il buffer "big-endian style" e poi leggo una variabile che parte allo stesso indirizzo del vettore (questo è quello che succede in pratica con quel cast) e l'architettura assume un byte order little-endian non ottengo il risultato che volevo. Quindi devo stare attento a come riempo il vettore.

Mi illuminate per favore invece su quale potrebbe essere il vero problema di allineamento a cui vi riferivate?

Grazie in anticipo.
Anyone who has never made a mistake has never tried anything new
Two things are infinite: universe and human stupidity, and I'm not sure about the former
You did not really understand something unless you can explain it to your grandmother
A. Einstein
Avatar utente
Foto UtenteShockwaver
770 1 5 11
Expert
Expert
 
Messaggi: 859
Iscritto il: 3 mar 2010, 18:56

1
voti

[13] Re: 64 bits cast in C99

Messaggioda Foto UtenteDirtyDeeds » 22 mag 2014, 21:42

Immagina di lavorare in un sistema in cui gli array di char possono essere allineati a qualunque indirizzo, mentre gli interi a 64 bit solo a indirizzi multipli di 8. Immagina allora che il puntatore corrispondente all'array parta dall'indirizzo 5: quel puntatore non può essere convertito a un puntatore ad unsigned long long.

In particolare lo standard del C dichiara (§6.3.2.3):

A pointer to an object type may be converted to a pointer to a different object type. If the
resulting pointer is not correctly aligned for the referenced type, the behavior is
undefined.
It's a sin to write sin instead of \sin (Anonimo).
...'cos you know that cos ain't \cos, right?
You won't get a sexy tan if you write tan in lieu of \tan.
Take a log for a fireplace, but don't take log for \logarithm.
Avatar utente
Foto UtenteDirtyDeeds
55,9k 7 11 13
G.Master EY
G.Master EY
 
Messaggi: 7012
Iscritto il: 13 apr 2010, 16:13
Località: Somewhere in nowhere

0
voti

[14] Re: 64 bits cast in C99

Messaggioda Foto UtenteShockwaver » 22 mag 2014, 21:45

Great!
Tutto chiaro, grazie ancora.
Una buona serata.
Anyone who has never made a mistake has never tried anything new
Two things are infinite: universe and human stupidity, and I'm not sure about the former
You did not really understand something unless you can explain it to your grandmother
A. Einstein
Avatar utente
Foto UtenteShockwaver
770 1 5 11
Expert
Expert
 
Messaggi: 859
Iscritto il: 3 mar 2010, 18:56

Precedente

Torna a PC e informatica

Chi c’è in linea

Visitano il forum: Nessuno e 19 ospiti