警告:隐式声明函数'getresuid'(和'seteuid') [英] warning: implicit declaration of function ‘getresuid’ (and ‘seteuid’)
问题描述
我想摆脱警告。当我使用
gcc -Wall -ansi -o test test.c
$ c>编译源代码时$ c>
我回来了
test。 c:函数'main'中:
test.c:12:警告:函数隐式声明'getresuid'
test.c:14:警告:函数隐式声明'seteuid'
当我使用 -ansi 开关进行编译时
gcc -Wall -o test test.c
<我在终端上看到
$ p $ test.c:在函数'main'中:
test.c:12 :警告:函数隐式声明'getresuid'
我想使用 -ansi 切换并摆脱警告。我怎样才能实现我的目标?
/ *这是test.c * /
#include
#include< sys / types.h>
#include< unistd.h>
#define __USE_GNU 1
#define __USE_BSD 1
int main()
{
static uid_t euid,ruid,suid;
getresuid(& ruid,& euid,& suid);
seteuid(getuid());
返回0;
$ / code>
环境:
CentOS 6.3 32位版本
gcc版本4.4.7 20120313(Red Hat 4.4.7-3)(GCC)
getresuid()
和 seteuid()
是GNU扩展函数,add
#define _GNU_SOURCE
pre>
之前包含所有标题,或者在GCC选项中添加
-D_GNU_SOURCE
。
您不应该直接定义
__ USE_GNU
宏,它应该只在glibc内部使用。I would like to get rid of the warnings. When I compile the source code with
gcc -Wall -ansi -o test test.c
I get back
test.c: In function ‘main’: test.c:12: warning: implicit declaration of function ‘getresuid’ test.c:14: warning: implicit declaration of function ‘seteuid’
When I compile it without -ansi switch
gcc -Wall -o test test.c
I see on the terminal
test.c: In function ‘main’: test.c:12: warning: implicit declaration of function ‘getresuid’
I would like to use -ansi switch and get rid of warnings. How can I achieve my goal ?
/* this is the test.c */ #include <stdio.h> #include <sys/types.h> #include <unistd.h> #define __USE_GNU 1 #define __USE_BSD 1 int main() { static uid_t euid, ruid, suid; getresuid(&ruid, &euid, &suid); seteuid(getuid()); return 0; }
Environment:
CentOS 6.3 32-bit
gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)
解决方案
getresuid()
andseteuid()
are GNU extension function, add#define _GNU_SOURCE
before including all the headers, or add
-D_GNU_SOURCE
in GCC options.You shouldn't define
__USE_GNU
macro directly, it's supposed to be used only internally in glibc.这篇关于警告:隐式声明函数'getresuid'(和'seteuid')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!