• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1894
  • Last Modified:

for loop not iterate more than 800000


i wrote a simple FOR LOOP  program in cocoa-objective c   (MAC os- compiler XCode). but it not working properly. the loop iterating  only upto some value near to 714300( value change each time running). program is given below.

#import <Cocoa/Cocoa.h>

int main(int argc, char *argv[])
   unsigned long long i=1;

       return NSApplicationMain(argc,  (const char **) argv);

if first printf statement is replaced as printf("%llu-",i); it iterate beyond 1000000 but it run very slowly( take nearly one hour to reach 1000000). what is the problem with this program.

  • 2
2 Solutions
What compiler are you using?

On my system, ULONG_LONG_MAX is 4,294,967,295

Therefore I'd expect my system to get rather 'warm' running your app here.

tariq6000Author Commented:
now  i am using mac mini -Tiger 10.4

compiler is Xcode
I doubt it needs that long to iterate that number of iterations. But an unsigned long long maximum is:
And that's really large number. You just reach a 0 after that many iteratoins
I suggest you write:

for ( i = 0; i < 10000000ULL; i++) {

if it's wise to printf for every number that often is another question....

On my machine

   for(; i < 10000000; )

takes around 50ms on average - a printf in the loop would add ages of course.

If the max value of an UUL is 18446744073709551615 on your implementation, the entire loop --

   for(; i < 18446744073709551615ULL; )

1844674407370 lots of 50ms to run - that's 92233720368547 ms, or - well, it's lots of time!  And that's without the printf calls!

My timing was just a crude couple of GetTickCount calls, so might not be super accurate.  And, please check my sums - watching the football as well as writing.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now