This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Why does 2nd loop only print values 10-19 and not 0-19?





It may be this should go to "gcc-help", due to my
not seeing my error, but....


 gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-suse-linux/4.9/lto-wrapper
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada,go --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.9 --enable-ssp --disable-libssp --disable-libvtv --disable-plugin --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --enable-linker-build-id --enable-linux-futex --program-suffix=-4.9 --without-system-libunwind --enable-multilib --with-arch-32=i586 --with-tune=generic --build=x86_64-suse-linux --host=x86_64-suse-linux
Thread model: posix
gcc version 4.9.0 (SUSE Linux)

----
Program:
-----------------

/* why does data printing loop start @ 10? */
/* linda w. (gcc(at)tlinx(dot)org */

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>


static int source[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };

int main(int argc, char **argv) {
   int i;
   int * dest= calloc(sizeof(source), sizeof(source[0]));
   int err = errno;

   if (!dest) {
fprintf(stderr, "Error, dest could not be allocated (errno=%d)\n", err);
       exit(1);
   }

   printf("for(i=0; i < %d)...\n", sizeof(source)/sizeof(source[0]));

   /* header */
   for (i==0; i < sizeof(source)/(2*sizeof(source[0])); ++i) {
       printf("  %2d--|",  i,0);
   }

   printf("\ndata:\n"); /* shouldn't nxt loop start @ '0' ? */

   for (i==0; i < sizeof(source)/sizeof(source[0]); i++) {
       printf(" %d:%2d;",  i, *(dest+i));
       if (i%10 == 9) printf("\n");
   }
   printf("\n");
}
-------
output:

for(i=0; i < 20)...
  0--|   1--|   2--|   3--|   4--|   5--|   6--|   7--|   8--|   9--|
data:
10: 0; 11: 0; 12: 0; 13: 0; 14: 0; 15: 0; 16: 0; 17: 0; 18: 0; 19: 0;






Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]