for loop not iterate more than 800000

Posted on 2007-10-09
Last Modified: 2013-11-25

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.

Question by:tariq6000
    LVL 10

    Expert Comment

    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.


    Author Comment

    now  i am using mac mini -Tiger 10.4

    compiler is Xcode
    LVL 24

    Accepted Solution

    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....

    LVL 10

    Assisted Solution

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Suggested Solutions

    Title # Comments Views Activity
    Adobe Customization Wizard XI issues 26 133
    scoresIncreasing challenge 10 47
    powerN  challenge 3 34
    firstChar challenge 13 55
    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
    The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now