08.04.2014 Views

Algorithmique et Langage - Pages de Michel Deloizy - Free

Algorithmique et Langage - Pages de Michel Deloizy - Free

Algorithmique et Langage - Pages de Michel Deloizy - Free

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.

Macros<br />

Définition <strong>de</strong> macros<br />

→ s’apparentent visuellement à <strong>de</strong>s fonctions, mais<br />

fonctionnement plus efficace<br />

→ fonctionnent par substitution <strong>de</strong> texte<br />

Exemple :<br />

#<strong>de</strong>fine<br />

MEAN(a,b) (a+b)/2<br />

à l’utilisation, on écrit : z = MEAN(x,2-i);<br />

le préprocesseur remplace la ligne par : z = (x+2-i)/2<br />

;<br />

→ les arguments ont été remplacés par substitution <strong>de</strong> texte<br />

→ la macro MEAN( ) a été remplacée par substitution <strong>de</strong> texte<br />

M. <strong>Deloizy</strong> <strong>Langage</strong> C<br />

113<br />

!! ATTENTION !!<br />

M. <strong>Deloizy</strong> <strong>Langage</strong> C<br />

114<br />

Exemple<br />

#<strong>de</strong>fine<br />

PRODUIT(u,v) u*v<br />

à l’utilisation : z = PRODUIT(3+2,5) ;<br />

donnera : z = 3+2*5 ; (13 au lieu <strong>de</strong> 25 ! )<br />

→ Utiliser <strong>de</strong>s parenthèses !<br />

Exemples :<br />

#<strong>de</strong>fine<br />

PRODUIT(u,v)<br />

u * v<br />

#<strong>de</strong>fine<br />

Mini(a,b) a < b ? a : b<br />

M. <strong>Deloizy</strong> <strong>Langage</strong> C<br />

115<br />

M. <strong>Deloizy</strong> <strong>Langage</strong> C<br />

116<br />

29

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

Saved successfully!

Ooh no, something went wrong!