Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

lazydog

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
I love how all these threads with originally simple questions turn into complex debates. No wonder the OPs usually never reply ;)

I totally agree with this!

By the way, not sure if this has been mentioned already, but I think there is something in the C standard that states unsigned int should ignore overflow, ie 0 = UINT_MAX + 1. It seems logical, at least to me, that this behaviour would also apply to unsigned long long which the OP is using.

b e n
 

Nishad

macrumors newbie
Original poster
Aug 2, 2007
11
0
You are not supposed to call NSApplicationMain thousands of times. You only call it once to initialize the application, load nibs and get a run loop started.

What in the world are you trying to do?



Thanks for the replys.
i was leave some day that is why the late reply,please excuse.

I dont want any infinte loop. i need loop that must iterate foa big value. i used long, unsigned long, int .... insted of unsigned long long but same thing happening.

i run the 'for loop program( written in C,C++) in windows using gcc compiler it works fine.
( i am using mac mini - Machine Name: Mac mini
Machine Model: Macmini1,1
CPU Type: Intel Core Duo
Number Of Cores: 2
CPU Speed: 1.66 GHz
L2 Cache (shared): 2 MB
Memory: 512 MB
Bus Speed: 667 MHz
Boot ROM Version: MM11.0055.B05
)
Actually in my original program 'for loop' have to iterarte more than 50000000( i wrote the program in cocoa -objective c). i tried the program with the value but i didnot get the desired output. then i found the problem was with for loop. then tried the simple program which i already written in forum and i realise the problem(not iteraring more than 714842(may change).

Then i changed the program as shown below

#import <Cocoa/Cocoa.h>

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

unsigned int j=0,k=0;
for(;i<=100000;++i)

printf("%llu\n",i);
for(;j<=300000;++j)

printf("%i\n",j);

for(;k<=500000;++k)

printf("%i\n",k);
printf("finished");
//printf("\n%llu",i++);

//printf("\r%llu",i);

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




the output is like this

first loop iterate foe 100000

second loop iterate for 300000

third loop iterate for only 314278

that is total iteration in program is 714278 !!

then stuck the program and i waited for 1 hour but it not showing any message or error and not terminated.

is it a problem with my system or program. i have no other mac system to check.

with regards and thanks
Nishad
 

lazydog

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
Perhaps I'm missing something here, but the probable cause of the problem has been pointed out already, ie your prints are filling up the terminal buffer or something like that.

How about trying this:-

Code:
unsigned long long i ;

for( i = 1 ;i != 0 ;++i)
  if ( i % 10000 == 0 )
     printf("%llu\n",i);

This will loop but only print every 10000th iteration. That way you can see that there is nothing strange going on with the loop as such, but the problem is down to the print buffer.

b e n
 

fimac

macrumors member
Jan 18, 2006
95
1
Finland
I dont want any infinte loop. i need loop that must iterate foa big value. i used long, unsigned long, int .... insted of unsigned long long but same thing happening.

As noted previously, there seems to be an output buffering issue, and probably the "hang" is related to whatever NSApplicationMain is doing. When something crazy happens, when your code behaves contrary to reason and logic, then it is vital that we go back to basics :)

Let's use terminal and gcc on your Mac. Let's change the program to emit only a few progress indicators (say one every 10000 iterations, for 50 total).
Code:
/* foo.c */
#include <stdio.h>
#include <assert.h>
int
main(void)
{
  unsigned k = 0;

  printf("running");
  for (; k <= 500000; ++k)
    {
      if ((k % 10000) == 0)
        printf(".");
    }
  printf("\n");
  assert(k == 500001);

  return 0;
}
Compilation and execution is easy from terminal. (The dollar-sign refers to the terminal prompt, don't type that!)
Code:
$ gcc -W -Wall -Werror -ansi -pedantic foo.c
$ ./a.out 
running...................................................
 

MongoTheGeek

macrumors 68040
Thanks for the replys.
i was leave some day that is why the late reply,please excuse.

that is total iteration in program is 714278 !!

then stuck the program and i waited for 1 hour but it not showing any message or error and not terminated.

is it a problem with my system or program. i have no other mac system to check.

with regards and thanks
Nishad

File a bug against XCode. Run from terminal the program works as expected. https://bugreport.apple.com/cgi-bin/WebObjects/RadarWeb.woa

There seems to be a 5M limit in the console contents.

714278*7 (6 digits and a newline)
 

Nishad

macrumors newbie
Original poster
Aug 2, 2007
11
0
Perhaps I'm missing something here, but the probable cause of the problem has been pointed out already, ie your prints are filling up the terminal buffer or something like that.

How about trying this:-

Code:
unsigned long long i ;

for( i = 1 ;i != 0 ;++i)
  if ( i % 10000 == 0 )
     printf("%llu\n",i);

This will loop but only print every 10000th iteration. That way you can see that there is nothing strange going on with the loop as such, but the problem is down to the print buffer.

b e n



thanks i got it.

with regards

Nishad
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.