Hi, Thank you for the clarification.
Best regards, István -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Przemyslaw Czerpak Sent: 2010. január 7. 7:42 To: Harbour Project Main Developer List. Subject: Re: [Harbour] C (++) question On Wed, 06 Jan 2010, Bisz István wrote: Hi, > In may analyzis of the assemble code of the: > if ( nSize == 0 ) nSize = 1;, > was more efficient that: > if ( !size ) size++; > at least with Keil C compiler for Dallas DS80C320, how do you think? Thank > you in advance. Yes in most of CPUs it's faster (but not all, i.e some CPUs have instruction to INC/DEC memory cell but have no instruction to assing direct value so such operation has to be done indirectly by register) and of course if( !size ) size = 1; is cleaner. I should not write the previous version and confuse user. Anyhow modern C compilers can fully optimize such C code and generate the same optimal code for both versions, i.e. try this: /* tst.c */ static int size = 0; void f1( void ) { if( !size ) size = 1; } void f2( void ) { if( !size ) size++; } void f3( void ) { if( !size ) ++size; } with gcc -O3 tst.c -S and you will find that for f1(), f2() and f3() the same code is generated. The difference is only with older compilers which do not make advanced optimizations. Sorry for confusion but each of us has some habits and I also was using 8 computers in the past and sometime I use some constructions which were better optimized but in this case I probably wanted to safe one character in example ;-) I do not even remember because it was unimportant for me and I know that it does not make any difference for advanced optimizations in modern C compilers. best regards, Przemek _______________________________________________ Harbour mailing list (attachment size limit: 40KB) [email protected] http://lists.harbour-project.org/mailman/listinfo/harbour _______________________________________________ Harbour mailing list (attachment size limit: 40KB) [email protected] http://lists.harbour-project.org/mailman/listinfo/harbour
