i was wondering whish is faster for(; or while(true) as for myself i think for(; is faster coz it doesnt chk if value is 1 is just keep going on and on
i was wondering whish is faster for(; or while(true) as for myself i think for(; is faster coz it doesnt chk if value is 1 is just keep going on and on
But I don't have a key...
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
I think most compilers will optimize that code down to the same assembler instructions anyway, so it doesn't matter.
QuantumPete
"No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
"Have you tried turning it off and on again?" - The IT Crowd
I remember reading in an old book about optimisation in C that noted that compilers regarded old at the time of writing would produce code that evaluated the constant expression in:
or more accurately, since true is a C++ keyword and C99 macro:Code:while (true)
but those same compilers would correctly produce "infinite loop" code when they encountered:Code:while (1)
No doubt this is not true of modern compilers, but it is of historical interest, and thus I decided to prefer the latter because it is arguably more "canonical"Code:for (;;)
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
becauseHmm, I wonder why that is.
could be a mistake and written instead ofCode:while(1)
for exampleCode:while(l)
On the same reason
could produce a warning about assignment in the if instead of comparisonCode:if(f=fopen...)
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
So do you think it is a good idea to subject people to warnings for mistakes they did not make?
Snafuist posted this rather amusing set of related facts the other day.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
I always get plenty of
warning C4706: assignment within conditional expression
when I do something like
When it's exactly what I want to say. But then I always use warning levels = 4 (highest).Code:if (!(lf = fopen(LOGFILE_NAME, "a"))) { printf("Failure to create or open logfile: %s\n", LOGFILE_NAME); ... }
Last edited by nonoob; 02-24-2009 at 05:46 PM.
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010