Reprise du message précédent :
alerim a écrit :
Il devait parler de cas où ça ne fait pas de différence a priori comme dans :
for (i = 0; i < j; ++i) { ... } |
par exemple. En C++ on préfère ++i à i++ si la valeur de i n'est pas utilisée dans l'expression car le jour où "i" est un objet autre qu'un simple entier, on peut avoir une perte de performance non négligeable. Mais sinon, dans le cas de C en particulier, ça ne fait pas différence.
|
L'assembleur n'est pas (plus) mon truc, mais la literrature informatique peut être intéressante. Dans l'art de la programmation, il y a des chapelles... A savourer !
Best Practices for Programming in C : http://www-106.ibm.com/developerwo [...] nxw02BestC
Morceau choisi :
Citation :
# Embedded statement
There is a time and a place for embedded assignment statements. In some constructs there is no better way to accomplish the results without resulting in bulkier and less readable code:
while ((c = getchar()) != EOF) {
process the character
}
Using embedded assignment statements to improve run-time performance is possible. However, you should consider the tradeoff between increased speed and decreased maintainability that results when embedded assignments are used in artificial places. For example:
x = y + z;
d = x + r;
should not be replaced by:
d = (x = y + z) + r;
even though the latter may save one cycle. In the long run the time difference between the two will decrease as the optimizer is enhanced, while the difference in ease of maintenance will increase.
|
Plus en rapport avec l'opérateur ternaire :
Optimal C Constructs for 8051 Microprocessors : http://www.embedded.com/story/OEG20021015S0046
Où l'auteur dit :
Citation :
The ternary operator is terse, slightly cryptic and a favorite of mine. Examination of K&R shows that the authors use the ternary operator very liberally indeed. But does the ternary operator actually accomplish anything? Well, the answer with the Keil compiler is an emphatic no, since it produces larger code and longer execution time in every test case I tried. Listing 5 shows Test Case 1 of the decision making project.
|
Conclusion : l'opérateur ternaire est à utiliser en connaissance de cause.
Bon WE
Message édité par pains-aux-raisins le 09-10-2004 à 15:32:23