This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

WouldBeNice/Optimisation: const variable-parameter-list for printf


 Hello,

 A lot of people (me too) write this kind of code:

 struct param1_str *param1;
 struct param2_str *param2;
 struct param3_str *param3;

 error = treat_alpha (param1, param2, param3);
 if (error)
    printf ("treat_alpha failed error %d, param1 = %p, "
            "param2 = %p, param3 = %p",
             error, param1, param2, param3);
 error = treat_beta (param1, param2, param3);
 if (error)
    printf ("treat_beta failed error %d, param1 = %p, "
            "param2 = %p, param3 = %p",
             error, param1, param2, param3);

 The printf() is only there for debug purposes, sometimes
it is msglog() or even sprintf().

 This construct cannot be optimised efficiently by the
compiler because the variable list of parameters of
printf() is not typed - so no "const" attribute, and even
a simple:
  printf ("error %d\n", error);
need to flush every registers to memory before the call and
reload everything after the call.

 It WouldBeNice to be able to prototype printf like:
int printf (const char *, const ...);
 and sprintf like:
int sprintf (char *, const char *, const ...);
 to at least reduce the number of reloads from memory
 to registers - because main memory will not changed
 when passing random type pointers, just displayed.

 I tried __attribute__ ((const)) but the effect is not
equivalent because when the return value is ignored the
call is removed.

 Just a WouldBeNice mail before Xmas... not even a patch.
 Etienne.



	

	
		
___________________________________________________________________________ 
Nouveau : téléphonez moins cher avec Yahoo! Messenger ! Découvez les tarifs exceptionnels pour appeler la France et l'international.
Téléchargez sur http://fr.messenger.yahoo.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]