Thread: Help About Nested Loop

  1. #1
    C/C++Newbie Antigloss's Avatar
    Join Date
    May 2005
    Posts
    216

    Help About Nested Loop

    Is there any limit on nested loop, say, maximun number of nested layers?

    Is there any computer now using 64-bit integer as type int?
    Last edited by Antigloss; 10-13-2006 at 08:42 AM.

  2. #2
    Registered User SKeane's Avatar
    Join Date
    Sep 2006
    Location
    England
    Posts
    234
    Stack size.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Quote Originally Posted by Antigloss
    Is there any limit on nested loop, say, maximun number of nested layers?
    Nope. There is a limmit on the total size of all stack variables, as SKeane said, but there are no limmits on nesting.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Actually, C89 specifies that a compiler must allow at least 8 (I think) levels of nested loops, and I believe it's 256 for C99.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Quote Originally Posted by dwks
    Actually, C89 specifies that a compiler must allow at least 8 (I think) levels of nested loops, and I believe it's 256 for C99.
    Hmm, I didn't know that. Well, there goes my idea with the 257 nested loops.

  6. #6
    and Nothing Else Matters
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    117
    256 nested loops? wow! thats a whopping O(256) running time..
    It is not who I am inside but what I do that defines me.

  7. #7
    C/C++Newbie Antigloss's Avatar
    Join Date
    May 2005
    Posts
    216
    Quote Originally Posted by C99
    5.2.4.1 Translation limits
    1 The implementation shall be able to translate and execute at least one program that
    13)
    contains at least one instance of every one of the following limits:
    — 127 nesting levels of blocks
    — 63 nesting levels of conditional inclusion
    Just found from C99 Standard. I believe it means the Standard guarantees just 63 nest levels of loops.

  8. #8
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by Antigloss
    Just found from C99 Standard. I believe it means the Standard guarantees just 63 nest levels of loops.
    The standard generally guarantees minimums, not maximums. Folks are free to create better things. Caveat emptor.

    Quote Originally Posted by Antigloss
    Is there any computer now using 64-bit integer as type int?
    http://en.wikipedia.org/wiki/64-bit#..._architectures
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  9. #9
    C/C++Newbie Antigloss's Avatar
    Join Date
    May 2005
    Posts
    216
    Quote Originally Posted by Dave_Sinkula
    It'll be better should you copy and paste those contents here coz I cannot access wikipedia for some reasons.

  10. #10
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by Antigloss
    It'll be better should you copy and paste those contents here coz I cannot access wikipedia for some reasons.
    M'kay.
    64-bit microprocessor architectures (as of 2006) include:

    * The DEC Alpha architecture (view Digital Alpha timeline)
    * Intel's IA-64 architecture (used in Intel's Itanium CPUs)
    * AMD's AMD64 architecture, a 64-bit version of the x86 architecture (used in AMD's Athlon 64, Opteron, Sempron, and Turion 64 CPUs).
    o Intel now uses the same instruction set, calling it EM64T.
    * SPARC architecture (64-bit as of SPARC V9)
    o Sun's UltraSPARC architecture
    o Fujitsu's SPARC64 architecture
    * IBM's POWER architecture (64-bit as of POWER3 and RS64 variants)
    * IBM/Motorola's PowerPC architecture (64-bit PowerPC 620 and PowerPC 970 variants)
    * IBM's z/Architecture, used by IBM zSeries and System z9 mainframes, a 64-bit version of the ESA/390 architecture
    * MIPS Technologies' MIPS IV, MIPS V, and MIPS64 architectures
    * HP's PA-RISC family (64-bit as of PA-RISC 2.0)

    Most 64-bit processor architectures can execute code for the 32-bit version of the architecture natively without any performance penalty. This kind of support is commonly called biarch support or more generally multi-arch support.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  11. #11
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Most 32-bit platforms today also support some form of 64-bit arithmetic; try using the C99 type long long x;
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  12. #12
    C/C++Newbie Antigloss's Avatar
    Join Date
    May 2005
    Posts
    216
    Sorry I didn't make my point clear. Let me try to make it clearer.

    C basic data type int is commonly 32-bit-long currently. Does any computer/compiler make int 64-bit-long instead of 32-bit-long?

  13. #13
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Yes, some newer 64-bit compilers, I think. I can't give you an actual example, but a Linux or Mac compiler for 64-bit processors might use 64-bit ints. I can check a 64-bit Debian Linux box that I have access to -- next time I get on it -- for you if you like.

    Why are you wondering? Just curious?

    Folks are free to create better things. Caveat emptor.
    My particular implementation of GCC allows over 3000 levels of indirection, dependent on how much of the stack was taken up by everything else.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  14. #14
    and Nothing Else Matters
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    117
    hey, i know this is a noob question but, what the difference between 32-bit compilers and 64-bit ones? please explain in an untechnical manner if you can please.
    It is not who I am inside but what I do that defines me.

  15. #15
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > — 127 nesting levels of blocks
    This of course refers to this within a single block of code.
    Code:
    for ( ... ) { /* 1 */
      for ( ... ) { /* 2 */
        for ( ... ) { /* 3 */
          for ( ... ) { /* 4 */
            /* etc etc */
            for ( ... ) { /* down to 127 */
            }
          }
        }
      }
    }
    The actual number of recursive levels for example is only limited by stack space.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. nested loop, simple but i'm missing it
    By big_brother in forum C Programming
    Replies: 19
    Last Post: 10-23-2006, 10:21 PM
  2. Nested for loop...search & display a list within a list
    By chadsxe in forum C++ Programming
    Replies: 13
    Last Post: 07-20-2005, 01:34 PM
  3. output from nested while loop
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 08-22-2002, 09:30 AM
  4. How to change recursive loop to non recursive loop
    By ooosawaddee3 in forum C Programming
    Replies: 1
    Last Post: 06-24-2002, 08:15 AM
  5. Need help with simple programs...
    By BCole19 in forum C++ Programming
    Replies: 22
    Last Post: 08-30-2001, 09:45 PM