title: More pointers to struct available than designated?
body: <p>Related Post: <a href="https://stackoverflow.com/questions/1149764/delete-folder-with-items">Delete folder with items</a></p>
  
  <p>How can more pointers in an array of pointers to struct be available for use than designated? For a learning tool for <strong>ftw/ftwn</strong>, I rewrote the ftwn solution in the related post (above) for ftw. Basically using the ftw callback to fill an array of structs containing the filename, type and depth for each file. File removal then proceeded from maxdepth to 0 removing files then directories along the way. This was a test, so <code>printf</code> shows where <code>unlink</code> or <code>rmdir</code> should be called and the removal commands are never executed.</p>
  
  <p>The storage for the array of structs was tried 3 different ways. (1) statically designating the number of pointers available <code>struct _rmstat *rmstat [100];</code>  (ftw 'nopenfd' set to 200), (2) dynamically allocating <code>struct _rmstat **rmstat;</code> and finally (3) adding the information to a linked list. Testing the static allocation, I specifically chose test directories with less than 100 files and then directories with <strong>more that 100 files, to cause failure</strong>.</p>
  
  <p>To my surprise, the statically allocated test would routinely handle directories containing well over 100 files, and up to as many as 450! How is that possible? I thought the static allocation <code>struct _rmstat *rmstat [100];</code> should guarantee a segfault (or similar core dump) when the 101st struct assignment was attempted. Is there something in gcc that does this in stack/heap allocation? Or, is this just part of what 'undefined' behavior is? With ftw, I set 'nopenfd' greater than the available struct pointers, so I don't think this is the result of ftw limiting file descriptors and closing/reopening files.</p>
  
  <p>I have searched, but can't find an explanation for how you possibly get more pointers than designated. Does anybody here know how this can happen?</p>
  
  <p>The <a href="http://www.3111skyline.com/dl/dev/prg/src/rmdir-ftw-static.c" rel="nofollow noreferrer">test program source</a> is available. <strong>It is safe - it deletes NOTHING</strong>, just prints with <code>printf</code>. Build with: <code>gcc -Wall  -o rmftws rmdir-ftw-static.c</code>  Thanks for any insight you can provide.</p>