[C] Question con sur printf

Question con sur printf [C] - C - Programmation

Marsh Posté le 23-08-2003 à 00:22:17    

Juste comme ca, ca a quel impact si dans un printf y a plus d'arguments que de champs % ?
 
exemple :
printf("%d", i, str, &truc);
 
je sais que ca compile sans pb, mais y a d'autres conséquences, comme pourriture de la pile, ou autres ?

Reply

Marsh Posté le 23-08-2003 à 00:22:17   

Reply

Marsh Posté le 23-08-2003 à 00:42:31    

ouais voila c la pile qui sen prend plein la g.....
 
essaie de compiler en mode release puis de le lancer peut etre que ca marchera moins bien  :whistle:  
 
enfait en assembleur se sera traduit comme ca :
 

Code :
  1. push "%d"
  2. push i
  3. push str 
  4. push &truc
  5. call _printf


 
reelement c des adresses qui sont poussees dans la pile mais bon la c pour simplifer....


Message édité par red faction le 23-08-2003 à 00:58:24
Reply

Marsh Posté le 23-08-2003 à 02:32:46    

Voici un petit extrait du draft de la spée du C (http://www.dkuug.dk/JTC1/SC22/WG14/www/docs/n843.htm)


       7.19.6.1  The fprintf function
 
       Synopsis
 
       [#1]
 
               #include <stdio.h>
               int fprintf(FILE * restrict stream,
                       const char * restrict format, ...);
 
       Description
 
       [#2] The  fprintf  function  writes  output  to  the  stream
       pointed to by stream, under control of the string pointed to
       by  format  that  specifies  how  subsequent  arguments  are
       converted  for  output.  If there are insufficient arguments
       for the format, the behavior is undefined.  If the format is
       exhausted  while  arguments remain, the excess arguments are
       evaluated  (as  always)  but  are  otherwise  ignored.   The
       fprintf  function  returns when the end of the format string
       is encountered.
 


 
et plus loin :
 


       7.19.6.3  The printf function
 
       Synopsis
 
       [#1]
 
               #include <stdio.h>
               int printf(const char * restrict format, ...);
 
       Description
 
       [#2]  The  printf function is equivalent to fprintf with the
       argument stdout interposed before the arguments to printf.


 
donc si il manque un argument le comportement est indéfini.
si il y a trop d'arguments, les arguments en trop sont évalués et  ignorés lors de l'écriture à l'écran.
 
Après le comportement exact dépendra de ta plateforme et de ton compilateur.

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed