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


Groups > comp.lang.c > #15857

Re: Compile error

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Compile error
Date 2012-01-16 14:17 -0800
Organization None to speak of
Message-ID <ln4nvv1edr.fsf@nuthaus.mib.org> (permalink)
References <5976423f-f7d5-40e6-b8fa-7636c8a8d8b7@a17g2000yqj.googlegroups.com> <lnsjjg1vhv.fsf@nuthaus.mib.org> <slrnjh86ga.1ls.grahn+nntp@frailea.sa.invalid> <lnd3aj1knb.fsf@nuthaus.mib.org> <877h0rtk96.fsf@blp.benpfaff.org>

Show all headers | View raw


blp@cs.stanford.edu (Ben Pfaff) writes:
> Keith Thompson <kst-u@mib.org> writes:
>> Jorgen Grahn <grahn+nntp@snipabacken.se> writes:
>>> On Sun, 2012-01-15, Keith Thompson wrote:
>>>> dspfun <dspfun@hotmail.com> writes:
>>>>> I get a compile/preprocessor error when trying to call/use the
>>>>> following line:
>>>>> openlog (__FUNCTION__, 0x02 | 0x01 | 0x08, (1<<3));
>>>>>
>>>>>
>>>>> The openlog function is declared as:
>>>>>
>>>>> extern void openlog (__const char *__ident, int __option, int
>>>>> __facility);
>>>>
>>>> Is "__const" a macro for "const"?  If so, why not just use "const"?
>>>> If it's to cater to compilers that don't support "const", I hardly think
>>>> that's necessary these days.
>>>>
>>>> Why are the parameter names reserved identifiers?  (The implementation
>>>> is free to define "__ident" as a macro, which would break the
>>>> declaration.)
>>>
>>> To be fair to Linux glibc (from where he must have copied the above),
>>> the manual page uses the normal names.
>>
>> So, dspfun, where did the identifiers __ident et al come from?
>
> On a glibc system:
>
>     blp@blp:~$ grep -r __ident /usr/include
>     /usr/include/sys/syslog.h:extern void openlog (__const char *__ident, int __option, int __facility);
>     blp@blp:~$ 

Ok, that makes some sense, given that /usr/include/sys/syslog.h is
part of the implementation.

The name of a parameter in a function declaration (as opposed to a
definition) is ignored; there's no way in C for a caller to refer
to a parameter by name.  The authors of syslog.h decided to use
reserved identifiers to avoid clashing with user-defined macros.
For example, if they had written:

    extern void openlog (__const char *ident, int option, int facility);

and a user wrote:

    #define ident 42
    #include <sys/syslog.h>

then the declaration would be a syntax error.

The lesson here is that system header files are intended for the
compiler, not necessarily for human readers (unless you have a
specific need to dive into the gory details); they can have all sorts
of implementation-defined cruft that's of no interest to most users.
The way to get the declaration for openlog() is to read the man page,
which says:

    #include <syslog.h>

    void openlog(const char *ident, int option, int facility);

As for __const, that's a gcc-specific "alternate keyword".
It probably goes back to the pre-ANSI days when some compilers didn't
support the "const" keyword.  It's equivalent (for gcc) to "const",
and there's no reason to use it or refer to it in your own code.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"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

Compile error dspfun <dspfun@hotmail.com> - 2012-01-15 08:14 -0800
  Re: Compile error NEON China BLUE <chine.bleu@yahoo.com> - 2012-01-15 08:29 -0800
    Re: Compile error dspfun <dspfun@hotmail.com> - 2012-01-15 08:32 -0800
      Re: Compile error dspfun <dspfun@hotmail.com> - 2012-01-15 09:07 -0800
  Re: Compile error "BartC" <bc@freeuk.com> - 2012-01-15 17:13 +0000
  Re: Compile error Keith Thompson <kst-u@mib.org> - 2012-01-15 13:55 -0800
    Re: Compile error Ian Collins <ian-news@hotmail.com> - 2012-01-16 11:25 +1300
    Re: Compile error Kaz Kylheku <kaz@kylheku.com> - 2012-01-15 23:28 +0000
    Re: Compile error Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-01-16 12:37 +0000
      Re: Compile error Keith Thompson <kst-u@mib.org> - 2012-01-16 12:02 -0800
        Re: Compile error blp@cs.stanford.edu (Ben Pfaff) - 2012-01-16 13:23 -0800
          Re: Compile error Keith Thompson <kst-u@mib.org> - 2012-01-16 14:17 -0800
            Re: Compile error dspfun <dspfun@hotmail.com> - 2012-01-17 03:40 -0800
        Re: Compile error Kaz Kylheku <kaz@kylheku.com> - 2012-01-16 21:51 +0000

csiph-web