Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Compile error

Reply
Thread Tools

Compile error

 
 
dspfun
Guest
Posts: n/a
 
      01-15-2012
Hi,

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);

The compiler error is:

------------------------------------------
powerpc-linux-gnu-gcc -c
....snip...
-Wno-write-strings foo.c -o foo.o
foo.c:62: error: expected declaration specifiers or '...' before
'__FUNCTION__'
....snip...
gmake[1]: *** [foo.o] Error 1
Command exited with non-zero status 2
------------------------------------------

Does anyone have any idea what the problem is and how to resolve it?

Brs,
Markus
 
Reply With Quote
 
 
 
 
dspfun
Guest
Posts: n/a
 
      01-15-2012
On 15 Jan, 17:29, NEON China BLUE <chine.b...@yahoo.com> wrote:
> In article <5976423f-f7d5-40e6-b8fa-7636c8a8d...@a17g2000yqj.googlegroups..com>,
>
> *dspfun <dsp...@hotmail.com> wrote:
> > Hi,

>
> > I get a compile/preprocessor error when trying to call/use the
> > following line:
> > openlog (__FUNCTION__, 0x02 | 0x01 | 0x08, (1<<3));

>
> Did you mean __func__?
>


I tried with __func__ as well instead of __FUNCTION__ but the same
error.

Any ideas?

Brs,
Markus
 
Reply With Quote
 
 
 
 
dspfun
Guest
Posts: n/a
 
      01-15-2012
On 15 Jan, 17:32, dspfun <dsp...@hotmail.com> wrote:
> On 15 Jan, 17:29, NEON China BLUE <chine.b...@yahoo.com> wrote:
>
> > In article <5976423f-f7d5-40e6-b8fa-7636c8a8d...@a17g2000yqj.googlegroups.com>,

>
> > *dspfun <dsp...@hotmail.com> wrote:
> > > Hi,

>
> > > I get a compile/preprocessor error when trying to call/use the
> > > following line:
> > > openlog (__FUNCTION__, 0x02 | 0x01 | 0x08, (1<<3));

>
> > Did you mean __func__?

>
> I tried with __func__ as well instead of __FUNCTION__ but the same
> error.
>
> Any ideas?
>
> Brs,
> Markus


Hi!

The problem is most likely related to that it's not possible to call
functions at file scope - they need to be inside another function.

The call to openlog() was actually embedded in a MACRO, which in turn
was embedded into another MACRO, so it was a bit confusing. The code I
put above had I extracted from after the preprocessor had been run..

Thanks!

Markus



 
Reply With Quote
 
BartC
Guest
Posts: n/a
 
      01-15-2012


"dspfun" <> wrote in message
news:5976423f-f7d5-40e6-b8fa-...
> Hi,
>
> 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);


> Does anyone have any idea what the problem is and how to resolve it?


What happens when __FUNCTION__ is replaced with NULL or 0? What happens when
you change __const to const (or leave it out altogether)?

--
Bartc

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      01-15-2012
dspfun <> 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.)

[...]

--
Keith Thompson (The_Other_Keith) kst- <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"
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      01-15-2012
On 01/16/12 10:55 AM, Keith Thompson wrote:
> dspfun<> 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.)


It looks like a bastardised version of the standard Unix function
declaration:

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

--
Ian Collins
 
Reply With Quote
 
Kaz Kylheku
Guest
Posts: n/a
 
      01-15-2012
On 2012-01-15, Keith Thompson <kst-> wrote:
> dspfun <> 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"?


Yes and no. GCC has such a keyword.

In the GNU C Library /usr/include/sys/cdefs.h we have this:

#ifdef __GNUC__

/* GCC can always grok prototypes. For C++ programs we add throw()
to help it optimize the function calls. But this works only with
gcc 2.8.x and egcs. For gcc 3.2 and up we even mark C functions
as non-throwing using a function attribute since programs can use
the -fexceptions options for C code as well. */
# if !defined __cplusplus && __GNUC_PREREQ (3, 3)
# define __THROW __attribute__ ((__nothrow__))
# define __NTH(fct) __attribute__ ((__nothrow__)) fct
# else
# if defined __cplusplus && __GNUC_PREREQ (2,
# define __THROW throw ()
# define __NTH(fct) fct throw ()
# else
# define __THROW
# define __NTH(fct) fct
# endif
# endif

#else /* Not GCC. */

# define __inline /* No inline functions. */

# define __THROW
# define __NTH(fct) fct

# define __const const
# define __signed signed
# define __volatile volatile

#endif /* GCC. */

> If it's to cater to compilers that don't support "const", I hardly think
> that's necessary these days.


It avoids unnecessary namespace pollution, I suppose. A program can use
const as a macro and it won't interfere with the GNU C Library headers.

*shrug*

Good questions for the glibc mailing list.
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      01-16-2012
On Sun, 2012-01-15, Keith Thompson wrote:
> dspfun <> 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.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      01-16-2012
Jorgen Grahn <grahn+> writes:
> On Sun, 2012-01-15, Keith Thompson wrote:
>> dspfun <> 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?

--
Keith Thompson (The_Other_Keith) kst- <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"
 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      01-16-2012
Keith Thompson <kst-> writes:

> Jorgen Grahn <grahn+> writes:
>> On Sun, 2012-01-15, Keith Thompson wrote:
>>> dspfun <> 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:~$
--
"I should killfile you where you stand, worthless human." --Kaz
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
compile directive for conditional compile for Java 1.4 versus Java 5 timjowers Java 7 02-02-2011 12:08 AM
How to compile the following source code in VC6// I have error inVC++6 but compile ok in GCC fAnSKyer C++ 2 06-07-2009 07:57 AM
computation at compile time i.e. compile time functions usingtemplates Carter C++ 2 03-04-2009 06:43 PM
Compile versus not compile (VS 2005)?? stupid48@gmail.com ASP .Net 1 04-11-2008 08:24 PM
cant compile on linux system.cant compile on cant compile onlinux system. Nagaraj C++ 1 03-01-2007 11:18 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57