C 警告:函数的隐式声明‘;getresuid’;(和seteuid)

C 警告:函数的隐式声明‘;getresuid’;(和seteuid),c,linux,gcc,compiler-warnings,gcc-warning,C,Linux,Gcc,Compiler Warnings,Gcc Warning,我想摆脱这些警告。当我用 gcc -Wall -ansi -o test test.c 我回来了 test.c: In function ‘main’: test.c:12: warning: implicit declaration of function ‘getresuid’ test.c:14: warning: implicit declaration of function ‘seteuid’ 当我编译它时没有-ansi开关 gcc -Wall -o test test.c

我想摆脱这些警告。当我用

gcc -Wall -ansi -o test test.c  
我回来了

test.c: In function ‘main’:
test.c:12: warning: implicit declaration of function ‘getresuid’
test.c:14: warning: implicit declaration of function ‘seteuid’
当我编译它时没有-ansi开关

gcc -Wall -o test test.c 
我在候机楼看到了

test.c: In function ‘main’:
test.c:12: warning: implicit declaration of function ‘getresuid’
我想使用-ansi开关并消除警告。我怎样才能实现我的目标

/*  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;
}
/*这是测试。c*/
#包括
#包括
#包括
#定义\u使用\u GNU 1
#定义\u使用\u BSD 1
int main()
{
静态uid\u t euid、ruid、suid;
getresuid(&ruid,&euid,&suid);
seteuid(getuid());
返回0;
}
环境:

CentOS 6.3 32位
gcc版本4.4.7 20120313(红帽4.4.7-3)(gcc)

getresuid()
seteuid()
是GNU扩展函数,添加

#define _GNU_SOURCE
之前包括所有标题,或在GCC选项中添加
-D_GNU__SOURCE


你不应该直接定义
\u使用\u GNU
宏,它应该只在glibc内部使用。

我已经添加(实现)了于浩提出的解决方案。原来的帖子反映了变化。我已经删除了你添加的解决方案部分,因为不是这样,你应该保持原样。@Yu Hao好吧,我注意到你已经从我的帖子中删除了详细的解决方案。老实说,我不明白为什么。我没有修改最初的帖子,我只是添加了解决方案。因为我是C语言的新手,所以我认为详细的解决方案可以帮助其他新手。人们喜欢以身作则,例如,看到“错误”的方法,然后看到“正确”的版本。它缩短了学习时间。但是,在我现在看来,这是不推荐的。我可以接受。你可以添加你的解决方案。但不要把它放在你的问题里,把它作为一个答案。是的,你可以回答你自己的问题。