这是标准的C? [英] is this stadard C?

查看:75
本文介绍了这是标准的C?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近第一次看到了一些东西:


int main(int argc,char ** argv,char ** envp)

^

我从未见过的东西是主函数的第三个arg。我认为主要是没有args或2 args。是不是这样?


洛厄尔

I saw something recently for the first time:

int main(int argc, char **argv, char **envp)
^
The thing I had never seen was a third arg to the main function. I
thought main either took no args or 2 args. Is this not the case?

Lowell

推荐答案

Lowell Kirsh写道:
Lowell Kirsh wrote:
我最近第一次看到了一些东西:

int main(int argc,char ** argv,char ** envp)
^
我从未见过是主要功能的第三个arg。我认为主要是不采取args或2 args。是不是这样?

洛厄尔
I saw something recently for the first time:

int main(int argc, char **argv, char **envp)
^
The thing I had never seen was a third arg to the main function. I
thought main either took no args or 2 args. Is this not the case?

Lowell




用于环境变量,这是一个标准的unix功能。


子流程继承父母的环境,这可以作为一个简单的进程间通信机制。

gtoomey
www.gregorytoomey.com


文章< cv ******** **@mughi.cs.ubc.ca> ;,

Lowell Kirsh< lk **** @ cs.ubc.ca>写道:
In article <cv**********@mughi.cs.ubc.ca>,
Lowell Kirsh <lk****@cs.ubc.ca> wrote:
我最近第一次看到了一些东西:

int main(int argc,char ** argv,char ** envp)
^
I saw something recently for the first time:

int main(int argc, char **argv, char **envp)
^
The thing I had never seen was a third arg to the main function. I
thought main either took no args or 2 args. Is this not the case?




这是严格符合在
托管实施下编译的程序的情况。


一个平台可以让你以任何方式定义主要的东西,

,因为除了

int main(void)以外的任何方式定义它



int main(int argc,char ** argv)

使编译器免于标准符号对它的要求/>
(在标准中,它调用未定义的行为),所以它可以做任何事情

(包括,作为最常见的情况,几乎它会做什么

如果你使用了正确的定义。)

C99试图通过这样说来合法化,除了两个

标准定义的main之外,它可以也可以用其他一些

实现定义的方式来定义;这真的没有改变任何东西,

虽然 - 你仍然踩到它定义的语言,如果你

有一个main()返回除了int或取任何东西

除了没有参数或标准指定的两个。


在这种特殊情况下,第三个指针作为main的参数是一个

(有点陈旧)的unixism,指向一系列环境

变量。获得这些标准的标准方法是使用

getenv(),POSIX也给你putenv()设置它们(我不确定

如果那可以通过envp指针)。

dave


-

Dave Vandervies dj ****** @ csclub.uwaterloo.ca

我想自动更新也会安装额外的记忆我需要

才能获得合理的表现。

- 复杂的英雄科尔文



This is the case for strictly conforming programs compiled under a
hosted implementation.

A platform can let you define main any way it wants to let you,
since defining it in any way other than
int main(void)
or
int main(int argc,char **argv)
frees the compiler from the requirements placed on it by the standard
(in standardese, it invokes undefined behavior), so it can do anything
(including, as the most frequent case, almost what it would have done
if you''d used the correct definition).
C99 attempted to legitimize this by saying that, in addition to the two
standard definitions of main, it can also be defined in "some other
implementation-defined manner"; this really doesn''t change anything,
though - you''re still stepping outside the language it defines if you
have a main() that returns anything other than int or takes anything
other than no arguments or the two specified by the standard.

In this particular case, a third pointer as an argument to main is a
(somewhat archaic) unixism that points to a collection of environment
variables. The standard-conforming way to get at these is to use
getenv(), and POSIX also gives you putenv() to set them (I''m not sure
if that''s possible through the envp pointer).
dave

--
Dave Vandervies dj******@csclub.uwaterloo.ca
I suppose automatic updates will also install the additional memory I need
to get reasonable performance.
--Alex Colvin in comp.arch


洛厄尔基尔什< LK **** @ cs.ubc.ca>写道:
Lowell Kirsh <lk****@cs.ubc.ca> writes:
我最近第一次看到了一些东西:

int main(int argc,char ** argv,char ** envp)
^
我从未见过的东西是主要功能的第三个arg。我认为主要是不采取args或2 args。是不是这样?
I saw something recently for the first time:

int main(int argc, char **argv, char **envp)
^
The thing I had never seen was a third arg to the main function. I
thought main either took no args or 2 args. Is this not the case?




是的,main()可能只能用零或两个

参数进行便携式定义。某些版本的Unix允许第三个参数用于
main(),但即使在Unix变体中也不是标准的。

-

" ;我应该杀死你,你站在哪里,毫无价值的人。 --Kaz



Yes, main() may only be portably defined with zero or two
parameters. Some versions of Unix allow a third parameter for
main(), but this is not standard even among Unix variants.
--
"I should killfile you where you stand, worthless human." --Kaz


这篇关于这是标准的C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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