Gentoo Archives: gentoo-user

From: Nilesh Govindarajan <contact@××××××××.com>
To: Gentoo User Mailing List <gentoo-user@l.g.o>
Subject: [gentoo-user] Strange GCC behavior
Date: Thu, 29 Sep 2011 17:30:57
Message-Id: 4E84AA7D.8080401@nileshgr.com
1 Default function arguments in C are specified like this:
2
3 int func(int a = 10) {} // just a dummy function
4
5 Now I save that in a file called foo.c
6
7 The above piece of code is valid in C as well as C++
8
9 Now see this:
10
11 nilesh@Linux ~ $ cat /tmp/foo.c
12 int func(int a = 1) {}
13 nilesh@Linux ~ $ gcc /tmp/foo.c
14 /tmp/foo.c:1:16: error: expected ‘;’, ‘,’ or ‘)’ before ‘=’ token
15 nilesh@Linux ~ $ g++ /tmp/foo.c
16 /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/../../../../lib64/crt1.o: In
17 function `_start':
18 (.text+0x20): undefined reference to `main'
19 collect2: ld returned 1 exit status
20 nilesh@Linux ~ $ gcc -v
21 Using built-in specs.
22 COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3/gcc
23 COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.5.3/lto-wrapper
24 Target: x86_64-pc-linux-gnu
25 Configured with:
26 /media/500GB/gentoo_portage/tmp/portage/sys-devel/gcc-4.5.3-r1/work/gcc-4.5.3/configure
27 --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3
28 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include
29 --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3
30 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/man
31 --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/info
32 --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include/g++-v4
33 --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec
34 --disable-fixed-point --without-ppl --without-cloog --disable-lto
35 --enable-nls --without-included-gettext --with-system-zlib
36 --disable-werror --enable-secureplt --enable-multilib
37 --enable-libmudflap --disable-libssp --enable-libgomp --enable-cld
38 --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/python
39 --enable-checking=release --disable-libgcj
40 --enable-languages=c,c++,fortran --enable-shared --enable-threads=posix
41 --enable-__cxa_atexit --enable-clocale=gnu
42 --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.5.3-r1
43 p1.0, pie-0.4.5'
44 Thread model: posix
45 gcc version 4.5.3 (Gentoo 4.5.3-r1 p1.0, pie-0.4.5)
46 nilesh@Linux ~ $ g++ -v
47 Using built-in specs.
48 COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3/g++
49 COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.5.3/lto-wrapper
50 Target: x86_64-pc-linux-gnu
51 Configured with:
52 /media/500GB/gentoo_portage/tmp/portage/sys-devel/gcc-4.5.3-r1/work/gcc-4.5.3/configure
53 --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3
54 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include
55 --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3
56 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/man
57 --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/info
58 --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include/g++-v4
59 --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec
60 --disable-fixed-point --without-ppl --without-cloog --disable-lto
61 --enable-nls --without-included-gettext --with-system-zlib
62 --disable-werror --enable-secureplt --enable-multilib
63 --enable-libmudflap --disable-libssp --enable-libgomp --enable-cld
64 --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/python
65 --enable-checking=release --disable-libgcj
66 --enable-languages=c,c++,fortran --enable-shared --enable-threads=posix
67 --enable-__cxa_atexit --enable-clocale=gnu
68 --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.5.3-r1
69 p1.0, pie-0.4.5'
70 Thread model: posix
71 gcc version 4.5.3 (Gentoo 4.5.3-r1 p1.0, pie-0.4.5)
72
73 Why is this happening? O_o
74
75 --
76 Nilesh Govindarajan
77 http://nileshgr.com

Replies

Subject Author
Re: [gentoo-user] Strange GCC behavior Michael Mol <mikemol@×××××.com>
Re: [gentoo-user] Strange GCC behavior Todd Goodman <tsg@×××××××××.net>
Re: [gentoo-user] Strange GCC behavior David W Noon <dwnoon@××××××××.com>