函数“ execle”错误的隐式声明 [英] implicit declaration of function 'execle' error

查看:84
本文介绍了函数“ execle”错误的隐式声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断得到


函数'execle'的隐式声明在C99中无效

implicit declaration of function 'execle' is invalid in C99

编译以下代码时。我想念什么?

when compiling the code below. What am I missing?

#include <stdio.h>
#include <stdlib.h>

char *my_env[] = {"JUICE=PEACH and apple", NULL};

int main (int argc, char *argv[])
{
  execle ("diner_info", "diner_info", "4", NULL, my_env);
  printf ("Diners: %s\n", argv[1]);
  printf ("Juice: %s\n", getenv("JUICE"));
  return 0;
}


推荐答案

C99 ,不允许隐式声明函数。这意味着,编译器在遇到对该函数的调用之前应该知道该函数签名。这可以通过两种方式实现:

In C99, the implicit declaration of a function is not allowed. That means, the compiler should be aware of the function signature before it encounters a call to that function. This can be achieved two ways: 


  1. 在使用函数之前先定义函数。

  2. 提供函数的正向声明并对其进行定义

通常,函数签名通过头文件作为前向声明提供。

Usually, the function signature is provided as a forward declaration through the header files.

根据手册页 execle(),您需要包含 unistd.h 才能获得前向声明。

As per the man page of execle(), you need to include unistd.h to get the forward declaration.

这篇关于函数“ execle”错误的隐式声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆