Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: The variable __func__ in C89 in gcc |
| Date | 2011-05-19 06:17 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <ir2qnj$ef8$1@dont-email.me> (permalink) |
| References | <ir0jt2$mol$1@news.albasani.net> <8890c1e6-61e2-48b9-96a0-b5c4599fb3ec@s14g2000vbi.googlegroups.com> |
On 05/19/2011 05:03 AM, Sorc Chan wrote:
> On 18 май, 18:08, rouben@shady.(none) (Rouben Rostamian) wrote:
>> Consider:
>>
>> #include <stdio.h>
>> int main(void)
>> {
>> printf("entering function %s\n", __func__);
>> return 0;
>>
>> }
>>
>> Gcc compiles this program without a warning, even
>> in C89 mode, as in "gcc -Wall -pedantic -std=c89 progname.c".
>>
>> I expected to see a warning since the identifier __func__ was
>> introduced in C99. Is there a good reason why the compilation
>> does not fail in the C89 mode?
>>
>> --
>> Rouben Rostamian
>
> int main(void) {
> __func__;
> return 0;
> }
>
> $ gcc -S main1.c -Wall -pedantic -std=c89 -o main1.s && cat main1.s
> main1.c: In function ‘main’:
> main1.c:2: warning: statement with no effect
> .file "main1.c"
> .text
> .globl main
> .type main, @function
> main:
> pushl %ebp
> movl %esp, %ebp
> movl $0, %eax
> popl %ebp
> ret
> .size main, .-main
> .section .rodata
> .type __func__.869, @object
> .size __func__.869, 5
> __func__.869:
> .string "main"
> .ident "GCC: (GNU) 4.4.4 20100630 (Red Hat 4.4.4-10)"
> .section .note.GNU-stack,"",@progbits
> $
>
> Dat GCC epic fail IMHO.
It might be an "epic failure" to meet some arbitrary requirement that
you've chosen to impose; but it does not indicate a failure to meet the
requirements imposed by the C89 standard.
>>> What would _prevent_ GCC from providing this for C89 code?
>
> Because __func__ in C98 undeclared such as any __ohhelloguys__ thing.
C89 imposes no such requirement. In fact, the main reason why the C89
standard said that a program using __func__ has undefined behavior is so
an implementation can choose to do anything it wishes to do with
__func__. In particular, the fact that the behavior is undefined gives
the compiler permission to treat __func__ as behaving in precisely the
fashion it's required to behave, according to the C99 standard. It also
gives it permission to treat __func__ as an indication that it should
use your program to generate Funk music.
--
James Kuyper
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
The variable __func__ in C89 in gcc rouben@shady.(none) (Rouben Rostamian) - 2011-05-18 14:08 +0000
Re: The variable __func__ in C89 in gcc Shao Miller <sha0.miller@gmail.com> - 2011-05-18 10:13 -0400
Re: The variable __func__ in C89 in gcc Seebs <usenet-nospam@seebs.net> - 2011-05-18 16:03 +0000
Re: The variable __func__ in C89 in gcc Keith Thompson <kst-u@mib.org> - 2011-05-18 10:32 -0700
Re: The variable __func__ in C89 in gcc cri@tiac.net (Richard Harter) - 2011-05-18 19:39 +0000
Re: The variable __func__ in C89 in gcc Seebs <usenet-nospam@seebs.net> - 2011-05-18 19:45 +0000
Re: The variable __func__ in C89 in gcc William Ahern <william@wilbur.25thandClement.com> - 2011-05-18 19:27 -0700
Re: The variable __func__ in C89 in gcc Keith Thompson <kst-u@mib.org> - 2011-05-19 08:42 -0700
Re: The variable __func__ in C89 in gcc Seebs <usenet-nospam@seebs.net> - 2011-05-19 16:34 +0000
Re: The variable __func__ in C89 in gcc Kenneth Brody <kenbrody@spamcop.net> - 2011-05-19 14:15 -0400
Re: The variable __func__ in C89 in gcc Shao Miller <sha0.miller@gmail.com> - 2011-05-19 14:45 -0400
Re: The variable __func__ in C89 in gcc Tim Rentsch <txr@alumni.caltech.edu> - 2011-05-19 14:02 -0700
Re: The variable __func__ in C89 in gcc Tim Rentsch <txr@alumni.caltech.edu> - 2011-05-19 12:45 -0700
Re: The variable __func__ in C89 in gcc Sorc Chan <sorcchan@gmail.com> - 2011-05-19 02:03 -0700
Re: The variable __func__ in C89 in gcc James Kuyper <jameskuyper@verizon.net> - 2011-05-19 06:17 -0400
Re: The variable __func__ in C89 in gcc Tim Rentsch <txr@alumni.caltech.edu> - 2011-05-19 13:44 -0700
Re: The variable __func__ in C89 in gcc Keith Thompson <kst-u@mib.org> - 2011-05-19 13:48 -0700
Re: The variable __func__ in C89 in gcc Tim Rentsch <txr@alumni.caltech.edu> - 2011-05-19 14:12 -0700
Re: The variable __func__ in C89 in gcc Keith Thompson <kst-u@mib.org> - 2011-05-19 14:29 -0700
Re: The variable __func__ in C89 in gcc gazelle@shell.xmission.com (Kenny McCormack) - 2011-05-19 21:54 +0000
Re: The variable __func__ in C89 in gcc Angel <angel+news@spamcop.net> - 2011-05-19 22:27 +0000
Re: The variable __func__ in C89 in gcc Tim Rentsch <txr@alumni.caltech.edu> - 2011-05-24 02:23 -0700
Re: The variable __func__ in C89 in gcc gazelle@shell.xmission.com (Kenny McCormack) - 2011-05-19 21:54 +0000
Re: The variable __func__ in C89 in gcc James Kuyper <jameskuyper@verizon.net> - 2011-05-19 23:26 -0400
Re: The variable __func__ in C89 in gcc Shao Miller <sha0.miller@gmail.com> - 2011-05-19 22:39 -0500
Re: The variable __func__ in C89 in gcc Shao Miller <sha0.miller@gmail.com> - 2011-05-19 08:22 -0400
Re: The variable __func__ in C89 in gcc Tim Rentsch <txr@alumni.caltech.edu> - 2011-05-19 13:47 -0700
csiph-web