Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #4236

Re: The variable __func__ in C89 in gcc

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: The variable __func__ in C89 in gcc
Date 2011-05-18 10:32 -0700
Organization None to speak of
Message-ID <lnmxij52zq.fsf@nuthaus.mib.org> (permalink)
References <ir0jt2$mol$1@news.albasani.net> <slrnit7reg.1ohi.usenet-nospam@guild.seebs.net>

Show all headers | View raw


Seebs <usenet-nospam@seebs.net> writes:
> On 2011-05-18, rouben@shady.(none) (Rouben Rostamian) <rouben@shady> wrote:
>> #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?
>
> Your code has undefined behavior.  Why should you have any expectations
> about what it does?  :)
>
> __func__ is in the implementation's namespace.  There is no lack of
> compliance with C89 if the implementation happens to define things in
> its own reserved namespace...

On the other hand, it would certainly be polite for gcc to warn about
this, at least in some mode.  The standard imposes no obligation to do
so, but gcc *knows* that __func__ specific to C99, and therefore that
any code that uses it is not portable to non-gcc C90 implementations.

Perhaps there's an option to do so; "-Wall" doesn't actually enable
*all* warnings (but a search of the gcc documentation didn't find such
an option).

(By "gcc knows", of course, I mean that the authors know, and could make
use of that knowedge to make gcc issue a warning.)

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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