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