# error: expected declaration specifiers or '...' before syslog

**URL:** <https://community.unix.com/t/error-expected-declaration-specifiers-or-before-syslog/277017>\
**Category:** Programming\
**Created:** [November 9, 2010, 12:07pm UTC](https://community.unix.com/t/error-expected-declaration-specifiers-or-before-syslog/277017 "2010-11-09T12:07:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dragonpoint](https://community.unix.com/letter_avatar/dragonpoint/32/6_449c533f586939b6e5f246632a46421f.png) [@dragonpoint](https://community.unix.com/u/dragonpoint)\
**Post date:** [November 9, 2010, 12:07pm UTC](https://community.unix.com/t/error-expected-declaration-specifiers-or-before-syslog/277017/1 "2010-11-09T12:07:24Z")

</div>

When I compile this i get the following error

```nohighlight
"error: expected declaration specifiers or '...' before syslog"

```

```nohighlight
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#define __LIBRARY__ 

#include <linux/unistd.h>

/* define the system call, to override the library function */
_syscall3(int, syslog, int, type, char *, bufp, int, len);

int main(int argc, char **argv)
{
    int level;

    if (argc==2) {
	level = atoi(argv[1]); /* the chosen console */
    } else {
        fprintf(stderr, "%s: need a single arg\n",argv[0]); exit(1);
    }
    if (syslog(8,NULL,level) < 0) {  
        fprintf(stderr,"%s: syslog(setlevel): %s\n",
                argv[0],strerror(errno));
        exit(1);
    }
    exit(0);
}

```

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_449c533f586939b6e5f246632a46421f.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [November 9, 2010, 12:15pm UTC](https://community.unix.com/t/error-expected-declaration-specifiers-or-before-syslog/277017/2 "2010-11-09T12:15:15Z")

</div>

You're using the wrong syslog, the kernel one instead of the libc one. The man page tells you to see man 3 syslog.

---

<div class="post-metadata">

**Author:** ![dragonpoint](https://community.unix.com/letter_avatar/dragonpoint/32/6_449c533f586939b6e5f246632a46421f.png) [@dragonpoint](https://community.unix.com/u/dragonpoint)\
**Post date:** [November 9, 2010, 12:26pm UTC](https://community.unix.com/t/error-expected-declaration-specifiers-or-before-syslog/277017/3 "2010-11-09T12:26:49Z")

</div>

Will the below code do the same thing because this one compiles without problems

```nohighlight
int syslog(int type, char *bufp, int len)
{
    return syscall(__NR_syslog, type, &bufp,len);
};

```

---

<div class="post-metadata">

**Author:** ![Loic\_Domaigne](https://community.unix.com/letter_avatar/loic_domaigne/32/6_449c533f586939b6e5f246632a46421f.png) [@Loic\_Domaigne](https://community.unix.com/u/Loic_Domaigne)\
**Post date:** [November 9, 2010, 12:30pm UTC](https://community.unix.com/t/error-expected-declaration-specifiers-or-before-syslog/277017/4 "2010-11-09T12:30:50Z")

</div>

seems that you're writing user space program (if I refer to your include), so syslog() from the glibc would be probably "better".  
man 3 syslog

Just my 2c,  
Lo�c

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_449c533f586939b6e5f246632a46421f.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [November 9, 2010, 1:16pm UTC](https://community.unix.com/t/error-expected-declaration-specifiers-or-before-syslog/277017/5 "2010-11-09T13:16:27Z")

</div>

You're writing a userspace program. Do you have a really good reason to be constructing your own system calls instead of using the ones glibc has already provided for this purpose?

---

<div class="post-metadata">

**Author:** ![dragonpoint](https://community.unix.com/letter_avatar/dragonpoint/32/6_449c533f586939b6e5f246632a46421f.png) [@dragonpoint](https://community.unix.com/u/dragonpoint)\
**Post date:** [November 9, 2010, 3:06pm UTC](https://community.unix.com/t/error-expected-declaration-specifiers-or-before-syslog/277017/6 "2010-11-09T15:06:58Z")

</div>

I was trying to define a custom system call only as an experiment....

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_449c533f586939b6e5f246632a46421f.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [November 9, 2010, 3:16pm UTC](https://community.unix.com/t/error-expected-declaration-specifiers-or-before-syslog/277017/7 "2010-11-09T15:16:29Z")

</div>

I see! In which case you might find `man 2 syscall` a better way to do arbitrary syscalls. I've certainly never managed to get \_syscall3 and the like to work...
