18.08.2013 Views

Dalla A alla Z passando per C - Robotica

Dalla A alla Z passando per C - Robotica

Dalla A alla Z passando per C - Robotica

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

o<strong>per</strong>andi sono un puntatore a struttura e il nome di un campo di tale struttura. È il modo più<br />

comune <strong>per</strong> utilizzare le strutture dati.<br />

#include <br />

/* st_mode è un campo intero di struct stat */<br />

struct stat st, *stptr, stvec[10];<br />

int i;<br />

/* funzione ipotetica */<br />

extern struct stat *getstatptr(int i);<br />

i = stptr->st_mode;<br />

i = (stvec+5)->st_mode;<br />

/* & tra parentesi, -> ha priorità maggiore */<br />

i = (&st)->st_mode;<br />

getstatptr(5)->st_mode;<br />

6.10 Negazione logica<br />

o<strong>per</strong>atore !<br />

sintassi ! espr<br />

n. o<strong>per</strong>andi 1<br />

punto esclamativo<br />

utilizzo negazione logica dell’espressione espr<br />

associativita’ ⇐=<br />

commutativita’ NO<br />

L’o<strong>per</strong>atore di negazione logica nega l’o<strong>per</strong>ando <strong>alla</strong> sua destra: se l’o<strong>per</strong>ando è 0 il risultato è<br />

1, se l’o<strong>per</strong>ando è non-zero il risultato è zero.<br />

p = malloc(128);<br />

if (!p) {<br />

/* gestione errore */<br />

}<br />

/* ritorna 0 se i vale 0, 1 se i e’ diverso da zero */<br />

return !!i;<br />

58

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!