Рассмотрим такой кусок кода:
int validInput;
double t = 0.0001;
double v[1], m[1], a[1];
double *y,*x;
y = (double*)malloc(max_recursion_number*sizeof(double));
x = (double*)malloc(max_recursion_number*sizeof(double));
if(x == NULL || y == NULL)
{
printf("Memory allocation failure, exiting.");
return(EXIT_FAILURE);
}
x[0] = 1;
y[0] = 0;
x[1] = -1;
y[1] = 0;
validInput = (argc == 7);
validInput = validInput && sscanf(argv[1],"%lf", &x[2]);
validInput = validInput && sscanf(argv[2],"%lf", &y[2]);
validInput = validInput && sscanf(argv[3],"%lf", &v[0]);
validInput = validInput && sscanf(argv[4],"%lf", &v[1]);
validInput = validInput && sscanf(argv[5],"%lf", &m[0]) && (m[0] >= 0);
validInput = validInput && sscanf(argv[6],"%lf", &m[1]) && (m[1] >= 0);
if(!validInput)
{
printf("Input validation failure, please use the program with x(0), y(0), vx(0), vy(0), m1, m2 as the commant line options, exiting. \n");
return(EXIT_FAILURE);
}
x[3] = x[2] + t*v[0];
y[3] = y[2] + t*v[1];
printf("%lf %lf %lf %lf \n", x[3], y[3], v[0], v[1]);
1.
primrose > uname -a
SunOS primrose 5.10 Generic_148888-05 sun4v sparc SUNW,SPARC-Enterprise-T5220
primrose > ./projv2 0 0 0 0 0 1
0.000100 0.000000 1.000000 0.000000
primrose > gcc -v
Using built-in specs.
Target: sparc-sun-solaris2.10
Configured with: ../gcc-4.4.2/configure --prefix=/usr/local/gnu --with-gmp=/usr/local
Thread model: posix
gcc version 4.4.2 (GCC)
2.
[tyakos@Kostya-PC proj]$ uname -a
Linux Kostya-PC 3.17.1-1-ARCH #1 SMP PREEMPT Wed Oct 15 15:04:35 CEST 2014 x86_64 GNU/Linux
[tyakos@Kostya-PC proj]$ gcc -lm projV2.c -oprojv2
[tyakos@Kostya-PC proj]$ ./projv2 0 0 0 0 0 1
0.000000 0.000000 0.000000 0.000000
[tyakos@Kostya-PC proj]$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /build/gcc/src/gcc-4.9.2/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-cloog-backend=isl --disable-isl-version-check --disable-cloog-version-check --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --disable-multilib --disable-werror --enable-checking=release
Thread model: posix
gcc version 4.9.2 (GCC)
Так вот, вопрос: у меня руки не из того места растут или это баг? В 2ом случае всё работает безукоризненно.