tobotras: (Default)
[personal profile] tobotras
Скажите, господа, как вы думаете, что, по-вашему, печатает на экране эта программа:

main()
{
printf( "%f\n", strtod( "0", 0 ) );
}

А что она на самом деле у вас печатает? А почему?

Date: 2004-12-10 07:05 am (UTC)
From: [identity profile] maxcom.livejournal.com
а я предупреждал, что функция, возвращающая не int - ересь :-)

Date: 2004-12-10 07:17 am (UTC)
From: [identity profile] kent-turbo.livejournal.com
Печатать должна 0.000, но не будет. Ибо implicitly defined strtod будет возвращать int вместо double. Поэтому напечатает какую-нибудь ересь.

Реально печатает -1.999210.

Хорошая шутка, ага. :)

Date: 2004-12-10 07:18 am (UTC)
From: [identity profile] kent-turbo.livejournal.com
Ересь не функция возвращающая не int, а ересь не использовать -Wall. :)

Date: 2004-12-10 07:18 am (UTC)
From: [identity profile] rmrfchik.livejournal.com
Сам ты ересь.

(lambda (make-eres x)
(lambda (y)
(+ (sin y) x)))

Date: 2004-12-10 07:20 am (UTC)
From: [identity profile] dil.livejournal.com
вот в таком виде - фигню всякую.
А если добавить правильный include, тогда 0.000000

Date: 2004-12-10 07:21 am (UTC)
From: [identity profile] bobuk.livejournal.com
Смеялись всем яндексом. Спасибо :)
From: [identity profile] erra.livejournal.com
> gcc -nostdinc -Wall -o test test.c
test.c: In function `main':
test.c:2: warning: implicit declaration of function `printf'
test.c:2: warning: implicit declaration of function `strtod'
test.c:2: warning: double format, different type arg (arg 2)
test.c:3: warning: control reaches end of non-void function
> ./test
0.000000
> uname -a
FreeBSD *** 5.3-STABLE FreeBSD 5.3-STABLE #16: Fri Nov 12 22:01:41 MSK 2004
> gcc -v
Using built-in specs.
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 3.4.2 [FreeBSD] 20040728

притом gcc 3.4.2 на Linux'е честно возвращает ахинею ;>

Date: 2004-12-10 07:31 am (UTC)
From: (Anonymous)
Фидошник :)

А что, была б какая-то ЛЖная аброкадабра -- что поменялось бы? :)
Все одно ж мы на 90% взаимно не знакомы.

вот

Date: 2004-12-10 07:33 am (UTC)
From: [identity profile] sha90w.livejournal.com
> cat 1.c
main()
{
printf( "%f\n", strtod( "0", 0 ) );
}
> gcc -o 1 -Wall 1.c
1.c:2: warning: return-type defaults to `int'
1.c: In function `main':
1.c:3: warning: implicit declaration of function `printf'
1.c:3: warning: implicit declaration of function `strtod'
1.c:3: warning: double format, different type arg (arg 2)
1.c:4: warning: control reaches end of non-void function
> ./1
0.000000
> gcc -v
Reading specs from /usr/lib/gcc-lib/i386-unknown-linux/2.95.3/specs
gcc version 2.95.3 20010315 (release)

дауж...

Date: 2004-12-10 07:38 am (UTC)
From: [identity profile] sha90w.livejournal.com
mci@drak:~$ ./1
-1.999184
mci@drak:~$ gcc -v
Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.4/specs
Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=gnu --enable-debug --enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc i486-linux
Thread model: posix
gcc version 3.3.4 (Debian 1:3.3.4-13)
From: [identity profile] dadcaptain.livejournal.com
и не морщится. Без варнингов на компиляции.

Re: вот

Date: 2004-12-10 07:51 am (UTC)
From: [identity profile] dottedmag.livejournal.com
Наверняка от какого-нибудь выравнивания все зависит. Ведь сначала мы пытаемся double выдать за int, а потом int за float.

Date: 2004-12-10 08:11 am (UTC)
From: [identity profile] dottedmag.livejournal.com
Еще более интересный результат:

[mag@vertex:~]$ gcc -Os -fomit-frame-pointer -o 1 1.c
[mag@vertex:~]$ ./1
2.425766
[mag@vertex:~]$ gcc -v
Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.4/specs
Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=gnu --enable-debug --enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc i486-linux
Thread model: posix
gcc version 3.3.4 (Debian 1:3.3.4-13)

Date: 2004-12-10 09:27 am (UTC)
From: [identity profile] dado.livejournal.com
0.000000
почему.. а почему бы и нет?
From: [identity profile] cvs.livejournal.com
у них в пузе подразумеваются прекомпиленные хидеры.

Date: 2004-12-10 02:38 pm (UTC)
From: [identity profile] xfyre.livejournal.com
2.546433

прикольно

Date: 2004-12-10 08:40 pm (UTC)
From: [identity profile] msh.livejournal.com
печатает платформенно-зависимую чушь при выполнении, warning при компиляции, ругательства при code review, настойчивые просьбы не пихать везде FP при design review. В обратном порядке.

Date: 2004-12-11 02:20 am (UTC)
From: [identity profile] k001.livejournal.com
У меня, по-моему, самый обалденный результат получился:

[kir@localhost ~]$ ./x
-3251965839102868998727633202116887135572776021213108627481971271454696864907279280040929743863128197238062668554407537734746197632782089588295327196786790703532399515551098493346865941027415604229049653145663552150827762249218412289553075602025329549281843065373504103301926818575526661809075296007094272.000000
[kir@localhost ~]$ gcc -v
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux
Thread model: posix
gcc version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)

На другой машинке

[kir@kir kir]$ ./x
-3007151235843787844031252807118764065651930054663668546624998770611799079827992116741604848640745186527582151292893148837069650258719029242943476438058618969047191363539587059621366466945346038569502176538580861400128657661433195916687609717101092279800097252100111192604091451054682130408251796192493568.000000
[kir@kir kir]$ gcc -v
Reading specs from /usr/lib/gcc-lib/athlon-asplinux-linux/3.3.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --disable-libunwind-exceptions --with-system-zlib --enable-__cxa_atexit --host=athlon-asplinux-linux
Thread model: posix
gcc version 3.3.3 20040216 (Red Hat Linux 3.3.3-2)


На третьей машинке примерно как и у всех:

mmx ~ # ./x
-1.998924
mmx ~ # gcc -v
Reading specs from /usr/lib/gcc-lib/i586-pc-linux-gnu/3.3.4/specs
Configured with: /var/tmp/portage/gcc-3.3.4-r1/work/gcc-3.3.4/configure --prefix=/usr --bindir=/usr/i586-pc-linux-gnu/gcc-bin/3.3 --includedir=/usr/lib/gcc-lib/i586-pc-linux-gnu/3.3.4/include --datadir=/usr/share/gcc-data/i586-pc-linux-gnu/3.3 --mandir=/usr/share/gcc-data/i586-pc-linux-gnu/3.3/man --infodir=/usr/share/gcc-data/i586-pc-linux-gnu/3.3/info --enable-shared --host=i586-pc-linux-gnu --target=i586-pc-linux-gnu --with-system-zlib --enable-languages=c,c++,f77 --enable-threads=posix --enable-long-long --disable-checking --disable-libunwind-exceptions --enable-cstdio=stdio --enable-version-specific-runtime-libs --with-gxx-include-dir=/usr/lib/gcc-lib/i586-pc-linux-gnu/3.3.4/include/g++-v3 --with-local-prefix=/usr/local --enable-shared --enable-nls --without-included-gettext --disable-multilib --enable-__cxa_atexit --enable-clocale=generic
Thread model: posix
gcc version 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6)

Profile

tobotras: (Default)
tobotras

December 2024

S M T W T F S
123 4567
891011121314
15161718192021
22232425262728
293031    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 13th, 2026 04:50 am
Powered by Dreamwidth Studios