PROJET AUTOBLOG


le hollandais volant links

Site original : le hollandais volant links

⇐ retour index

There is no 'printf'.

vendredi 22 octobre 2021 à 12:57
As so often when debugging something that doesn't make sense, we need to determine if what we're looking at is actually what we think we're looking at. We wrote some code, and we run an executable, but who's to say that the executable uses the exact instructions we wrote into the code?

C is not an interpreted language, but a compiled language, meaning we use a tool -- a compiler -- to translate our high-level code into machine instructions. And if you remember the various stages of a compiler, you'll note that one of them includes code optimization. So let's take a look at what exactly our compiler produces:

Parfois, les compilateurs remplacent certaines fonctions que vous écrivez par d’autres qu’ils jugent plus appropriées. Et ça peut provoquer des désagréments. Ici, printf() retourne la longueur de la chaîne affichée. Mais le compilateur peut le remplacer par une fonction qui retourne autre chose (ici, puts(), qui retourne un code, pas la longueur de la chaîne passée en paramètres).


— (permalink)