* [gentoo-user] Strange GCC behavior
@ 2011-09-29 17:27 Nilesh Govindarajan
2011-09-29 17:40 ` Michael Mol
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Nilesh Govindarajan @ 2011-09-29 17:27 UTC (permalink / raw
To: Gentoo User Mailing List
Default function arguments in C are specified like this:
int func(int a = 10) {} // just a dummy function
Now I save that in a file called foo.c
The above piece of code is valid in C as well as C++
Now see this:
nilesh@Linux ~ $ cat /tmp/foo.c
int func(int a = 1) {}
nilesh@Linux ~ $ gcc /tmp/foo.c
/tmp/foo.c:1:16: error: expected ‘;’, ‘,’ or ‘)’ before ‘=’ token
nilesh@Linux ~ $ g++ /tmp/foo.c
/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/../../../../lib64/crt1.o: In
function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
nilesh@Linux ~ $ gcc -v
Using built-in specs.
COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.5.3/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with:
/media/500GB/gentoo_portage/tmp/portage/sys-devel/gcc-4.5.3-r1/work/gcc-4.5.3/configure
--prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include/g++-v4
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec
--disable-fixed-point --without-ppl --without-cloog --disable-lto
--enable-nls --without-included-gettext --with-system-zlib
--disable-werror --enable-secureplt --enable-multilib
--enable-libmudflap --disable-libssp --enable-libgomp --enable-cld
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/python
--enable-checking=release --disable-libgcj
--enable-languages=c,c++,fortran --enable-shared --enable-threads=posix
--enable-__cxa_atexit --enable-clocale=gnu
--with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.5.3-r1
p1.0, pie-0.4.5'
Thread model: posix
gcc version 4.5.3 (Gentoo 4.5.3-r1 p1.0, pie-0.4.5)
nilesh@Linux ~ $ g++ -v
Using built-in specs.
COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3/g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.5.3/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with:
/media/500GB/gentoo_portage/tmp/portage/sys-devel/gcc-4.5.3-r1/work/gcc-4.5.3/configure
--prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include/g++-v4
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec
--disable-fixed-point --without-ppl --without-cloog --disable-lto
--enable-nls --without-included-gettext --with-system-zlib
--disable-werror --enable-secureplt --enable-multilib
--enable-libmudflap --disable-libssp --enable-libgomp --enable-cld
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/python
--enable-checking=release --disable-libgcj
--enable-languages=c,c++,fortran --enable-shared --enable-threads=posix
--enable-__cxa_atexit --enable-clocale=gnu
--with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.5.3-r1
p1.0, pie-0.4.5'
Thread model: posix
gcc version 4.5.3 (Gentoo 4.5.3-r1 p1.0, pie-0.4.5)
Why is this happening? O_o
--
Nilesh Govindarajan
http://nileshgr.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [gentoo-user] Strange GCC behavior
2011-09-29 17:27 [gentoo-user] Strange GCC behavior Nilesh Govindarajan
@ 2011-09-29 17:40 ` Michael Mol
2011-09-29 17:47 ` Nilesh Govindarajan
2011-09-29 17:43 ` Todd Goodman
2011-09-29 18:00 ` David W Noon
2 siblings, 1 reply; 7+ messages in thread
From: Michael Mol @ 2011-09-29 17:40 UTC (permalink / raw
To: gentoo-user
On Thu, Sep 29, 2011 at 1:27 PM, Nilesh Govindarajan
<contact@nileshgr.com> wrote:
> Default function arguments in C are specified like this:
>
> int func(int a = 10) {} // just a dummy function
>
> Now I save that in a file called foo.c
>
> The above piece of code is valid in C as well as C++
>
> Now see this:
>
> nilesh@Linux ~ $ cat /tmp/foo.c
> int func(int a = 1) {}
> nilesh@Linux ~ $ gcc /tmp/foo.c
> /tmp/foo.c:1:16: error: expected ‘;’, ‘,’ or ‘)’ before ‘=’ token
> nilesh@Linux ~ $ g++ /tmp/foo.c
> /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/../../../../lib64/crt1.o: In
> function `_start':
> (.text+0x20): undefined reference to `main'
> collect2: ld returned 1 exit status
> nilesh@Linux ~ $ gcc -v
> Using built-in specs.
> COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3/gcc
> COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.5.3/lto-wrapper
> Target: x86_64-pc-linux-gnu
> Configured with:
> /media/500GB/gentoo_portage/tmp/portage/sys-devel/gcc-4.5.3-r1/work/gcc-4.5.3/configure
> --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3
> --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include
> --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3
> --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/man
> --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/info
> --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include/g++-v4
> --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec
> --disable-fixed-point --without-ppl --without-cloog --disable-lto
> --enable-nls --without-included-gettext --with-system-zlib
> --disable-werror --enable-secureplt --enable-multilib
> --enable-libmudflap --disable-libssp --enable-libgomp --enable-cld
> --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/python
> --enable-checking=release --disable-libgcj
> --enable-languages=c,c++,fortran --enable-shared --enable-threads=posix
> --enable-__cxa_atexit --enable-clocale=gnu
> --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.5.3-r1
> p1.0, pie-0.4.5'
> Thread model: posix
> gcc version 4.5.3 (Gentoo 4.5.3-r1 p1.0, pie-0.4.5)
> nilesh@Linux ~ $ g++ -v
> Using built-in specs.
> COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3/g++
> COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.5.3/lto-wrapper
> Target: x86_64-pc-linux-gnu
> Configured with:
> /media/500GB/gentoo_portage/tmp/portage/sys-devel/gcc-4.5.3-r1/work/gcc-4.5.3/configure
> --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3
> --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include
> --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3
> --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/man
> --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/info
> --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include/g++-v4
> --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec
> --disable-fixed-point --without-ppl --without-cloog --disable-lto
> --enable-nls --without-included-gettext --with-system-zlib
> --disable-werror --enable-secureplt --enable-multilib
> --enable-libmudflap --disable-libssp --enable-libgomp --enable-cld
> --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/python
> --enable-checking=release --disable-libgcj
> --enable-languages=c,c++,fortran --enable-shared --enable-threads=posix
> --enable-__cxa_atexit --enable-clocale=gnu
> --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.5.3-r1
> p1.0, pie-0.4.5'
> Thread model: posix
> gcc version 4.5.3 (Gentoo 4.5.3-r1 p1.0, pie-0.4.5)
>
> Why is this happening? O_o
First guess, you need an int main() function, or you need to tell gcc
not to look for one.
--
:wq
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [gentoo-user] Strange GCC behavior
2011-09-29 17:27 [gentoo-user] Strange GCC behavior Nilesh Govindarajan
2011-09-29 17:40 ` Michael Mol
@ 2011-09-29 17:43 ` Todd Goodman
2011-09-29 17:50 ` Michael Mol
2011-09-29 17:54 ` Nilesh Govindarajan
2011-09-29 18:00 ` David W Noon
2 siblings, 2 replies; 7+ messages in thread
From: Todd Goodman @ 2011-09-29 17:43 UTC (permalink / raw
To: gentoo-user
* Nilesh Govindarajan <contact@nileshgr.com> [110929 13:33]:
> Default function arguments in C are specified like this:
>
> int func(int a = 10) {} // just a dummy function
No they're not. C doesn't have default function arguments.
>
> Now I save that in a file called foo.c
>
> The above piece of code is valid in C as well as C++
Uh, no it's not.
>
> Why is this happening? O_o
Because it's not correct C.
Todd
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [gentoo-user] Strange GCC behavior
2011-09-29 17:40 ` Michael Mol
@ 2011-09-29 17:47 ` Nilesh Govindarajan
0 siblings, 0 replies; 7+ messages in thread
From: Nilesh Govindarajan @ 2011-09-29 17:47 UTC (permalink / raw
To: gentoo-user
On Thu 29 Sep 2011 11:10:00 PM IST, Michael Mol wrote:
> On Thu, Sep 29, 2011 at 1:27 PM, Nilesh Govindarajan
> <contact@nileshgr.com> wrote:
>> Default function arguments in C are specified like this:
>>
>> int func(int a = 10) {} // just a dummy function
>>
>> Now I save that in a file called foo.c
>>
>> The above piece of code is valid in C as well as C++
>>
>> Now see this:
>>
>> nilesh@Linux ~ $ cat /tmp/foo.c
>> int func(int a = 1) {}
>> nilesh@Linux ~ $ gcc /tmp/foo.c
>> /tmp/foo.c:1:16: error: expected ‘;’, ‘,’ or ‘)’ before ‘=’ token
>> nilesh@Linux ~ $ g++ /tmp/foo.c
>> /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/../../../../lib64/crt1.o: In
>> function `_start':
>> (.text+0x20): undefined reference to `main'
>> collect2: ld returned 1 exit status
>> nilesh@Linux ~ $ gcc -v
>> Using built-in specs.
>> COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3/gcc
>> COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.5.3/lto-wrapper
>> Target: x86_64-pc-linux-gnu
>> Configured with:
>> /media/500GB/gentoo_portage/tmp/portage/sys-devel/gcc-4.5.3-r1/work/gcc-4.5.3/configure
>> --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3
>> --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include
>> --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3
>> --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/man
>> --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/info
>> --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include/g++-v4
>> --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec
>> --disable-fixed-point --without-ppl --without-cloog --disable-lto
>> --enable-nls --without-included-gettext --with-system-zlib
>> --disable-werror --enable-secureplt --enable-multilib
>> --enable-libmudflap --disable-libssp --enable-libgomp --enable-cld
>> --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/python
>> --enable-checking=release --disable-libgcj
>> --enable-languages=c,c++,fortran --enable-shared --enable-threads=posix
>> --enable-__cxa_atexit --enable-clocale=gnu
>> --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.5.3-r1
>> p1.0, pie-0.4.5'
>> Thread model: posix
>> gcc version 4.5.3 (Gentoo 4.5.3-r1 p1.0, pie-0.4.5)
>> nilesh@Linux ~ $ g++ -v
>> Using built-in specs.
>> COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3/g++
>> COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.5.3/lto-wrapper
>> Target: x86_64-pc-linux-gnu
>> Configured with:
>> /media/500GB/gentoo_portage/tmp/portage/sys-devel/gcc-4.5.3-r1/work/gcc-4.5.3/configure
>> --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3
>> --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include
>> --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3
>> --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/man
>> --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/info
>> --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include/g++-v4
>> --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec
>> --disable-fixed-point --without-ppl --without-cloog --disable-lto
>> --enable-nls --without-included-gettext --with-system-zlib
>> --disable-werror --enable-secureplt --enable-multilib
>> --enable-libmudflap --disable-libssp --enable-libgomp --enable-cld
>> --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/python
>> --enable-checking=release --disable-libgcj
>> --enable-languages=c,c++,fortran --enable-shared --enable-threads=posix
>> --enable-__cxa_atexit --enable-clocale=gnu
>> --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.5.3-r1
>> p1.0, pie-0.4.5'
>> Thread model: posix
>> gcc version 4.5.3 (Gentoo 4.5.3-r1 p1.0, pie-0.4.5)
>>
>> Why is this happening? O_o
>
> First guess, you need an int main() function, or you need to tell gcc
> not to look for one.
>
>
Syntax error doesn't depend on existence of main. I just posted this as
a snippet, I'd been working on one of my practical programs and
spotted this problem with a function I'd just made. And yeah, my
program had main().
--
Nilesh Govindarajan
http://nileshgr.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [gentoo-user] Strange GCC behavior
2011-09-29 17:43 ` Todd Goodman
@ 2011-09-29 17:50 ` Michael Mol
2011-09-29 17:54 ` Nilesh Govindarajan
1 sibling, 0 replies; 7+ messages in thread
From: Michael Mol @ 2011-09-29 17:50 UTC (permalink / raw
To: gentoo-user
On Thu, Sep 29, 2011 at 1:43 PM, Todd Goodman <tsg@bonedaddy.net> wrote:
> * Nilesh Govindarajan <contact@nileshgr.com> [110929 13:33]:
>> Default function arguments in C are specified like this:
>>
>> int func(int a = 10) {} // just a dummy function
>
> No they're not. C doesn't have default function arguments.
That's another problem. (I don't know if gcc extends C to that end, though)
This may be useful once he gets there:
https://gustedt.wordpress.com/2010/06/03/default-arguments-for-c99/
--
:wq
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [gentoo-user] Strange GCC behavior
2011-09-29 17:43 ` Todd Goodman
2011-09-29 17:50 ` Michael Mol
@ 2011-09-29 17:54 ` Nilesh Govindarajan
1 sibling, 0 replies; 7+ messages in thread
From: Nilesh Govindarajan @ 2011-09-29 17:54 UTC (permalink / raw
To: gentoo-user
On Thu 29 Sep 2011 11:13:54 PM IST, Todd Goodman wrote:
> * Nilesh Govindarajan <contact@nileshgr.com> [110929 13:33]:
>> Default function arguments in C are specified like this:
>>
>> int func(int a = 10) {} // just a dummy function
>
> No they're not. C doesn't have default function arguments.
>
>>
>> Now I save that in a file called foo.c
>>
>> The above piece of code is valid in C as well as C++
>
> Uh, no it's not.
>
>>
>> Why is this happening? O_o
>
> Because it's not correct C.
>
> Todd
Gah! so that's the reason. I've been coding C++ and other languages
with default arguments that I forgot C.
--
Nilesh Govindarajan
http://nileshgr.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [gentoo-user] Strange GCC behavior
2011-09-29 17:27 [gentoo-user] Strange GCC behavior Nilesh Govindarajan
2011-09-29 17:40 ` Michael Mol
2011-09-29 17:43 ` Todd Goodman
@ 2011-09-29 18:00 ` David W Noon
2 siblings, 0 replies; 7+ messages in thread
From: David W Noon @ 2011-09-29 18:00 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 797 bytes --]
On Thu, 29 Sep 2011 22:57:25 +0530, Nilesh Govindarajan wrote about
[gentoo-user] Strange GCC behavior:
> Default function arguments in C are specified like this:
>
> int func(int a = 10) {} // just a dummy function
>
> Now I save that in a file called foo.c
>
> The above piece of code is valid in C as well as C++
Not in C90. The default grammar does not permit default values for
arguments in C, only C++.
> Why is this happening? O_o
Try adding -std=gnu99 as a compiler switch. That switches the grammar
from C90 to C99, with Gnu extensions too.
--
Regards,
Dave [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
dwnoon@ntlworld.com (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-09-29 18:02 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-29 17:27 [gentoo-user] Strange GCC behavior Nilesh Govindarajan
2011-09-29 17:40 ` Michael Mol
2011-09-29 17:47 ` Nilesh Govindarajan
2011-09-29 17:43 ` Todd Goodman
2011-09-29 17:50 ` Michael Mol
2011-09-29 17:54 ` Nilesh Govindarajan
2011-09-29 18:00 ` David W Noon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox