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