c标准中存在哪些主要声明? [英] What declarations of main exist in the c standard?
问题描述
嗨。
我和一位朋友讨论了主要问题。在我看来,合法写的主要方式是:
int main(void);
int main(int, char **);
我的朋友声称你也有环境标准版
这样的变量:
int main(int,char **,char **);
这是正确的还是我的两个版本是唯一标准的c方式呢?
-
bjrnove
Hi.
Me and a friend have a discussion about main. In my opinion the legal
ways of writing main is:
int main(void);
int main(int,char**);
My friend claims that you also have a standard version with enviroment
variables like this:
int main(int,char**,char**);
Is that right or are my two versions the only standard c way to do it?
--
bjrnove
推荐答案
bjrnove写道:
bjrnove wrote:
嗨。
我和一位朋友讨论了主要内容。在我看来,合法写主要的方式是:
int main(void);
int main(int,char **);
我的朋友声称你也有一个带有环境的标准版本
这样的变量:
int main(int,char **,char **);
是吗或者我的两个版本是唯一标准的c方式吗?
Hi.
Me and a friend have a discussion about main. In my opinion the legal
ways of writing main is:
int main(void);
int main(int,char**);
My friend claims that you also have a standard version with enviroment
variables like this:
int main(int,char**,char**);
Is that right or are my two versions the only standard c way to do it?
标准保证任何托管的C实现
必须接受你的两个形式。标准允许实现
也接受其他形式,但没有描述任何这些
特定于实现的替代形式,并且不需要
其他实现接受它们。
换句话说:你描述的两种形式是
只有两种形式可以保证工作所有实现。
替代非标准表单可能适用于某些实现,
但不需要全部工作 - 甚至不需要它们
以同样的方式为他们工作
的所有实施工作。
-
Eric Sosman
es*****@acm-dot-org.inva lid
The Standard guarantees that any hosted C implementation
must accept your two forms. The Standard allows an implementation
to accept other forms, too, but does not describe any of those
implementation-specific alternative forms and does not require that
other implementations accept them.
To put it another way: The two forms you describe are the
only two forms that are guaranteed to work on all implementations.
Alternative non-Standard forms may work on some implementations,
but are not required to work on all -- they are not even required
to work in the same way for all implementations where they "work"
at all.
--
Eric Sosman
es*****@acm-dot-org.invalid
>标准保证任何托管的C实现
> The Standard guarantees that any hosted C implementation
必须接受您的两个表单。标准允许实现
接受其他形式,但不描述任何特定于实现的替代形式,并且不要求其他实现接受它们。
换句话说:你描述的两种形式是
只有两种形式可以保证适用于所有实现。
替代的非标准形式可能适用于某些实现,
但并不需要全部工作 - 甚至不需要它们以相同的方式工作,以便它们完全工作的所有实现。
must accept your two forms. The Standard allows an implementation
to accept other forms, too, but does not describe any of those
implementation-specific alternative forms and does not require that
other implementations accept them. To put it another way: The two forms you describe are the
only two forms that are guaranteed to work on all implementations.
Alternative non-Standard forms may work on some implementations,
but are not required to work on all -- they are not even required
to work in the same way for all implementations where they "work"
at all.
>
正如我的方式那样。谢谢..
-
bjrnove
Exactly the way I though it was. Thanks..
--
bjrnove
文章< 11 ***********************g47g2000cwa.googlegroups .com> ;,
bjrnove< bj ***** @ gmail。 COM>写道:
In article <11**********************@g47g2000cwa.googlegroups .com>,
bjrnove <bj*****@gmail.com> wrote:
标准保证任何托管的C实现
必须接受您的两个表单。标准允许实现接受其他形式,但不描述任何特定于实现的替代形式,并且不要求其他实现接受它们。
The Standard guarantees that any hosted C implementation
must accept your two forms. The Standard allows an implementation
to accept other forms, too, but does not describe any of those
implementation-specific alternative forms and does not require that
other implementations accept them.
正是我的方式。谢谢..
Exactly the way I though it was. Thanks..
第三个参数与环境变量的存在
信息是一个常见的Unix扩展 - 但它不是甚至
部分Unix规范(导入POSIX.1
规范):
http://www.opengroup.org/onlinepubs/...ions/exec.html
exec系列函数将用新的过程映像替换当前进程
映像。新图像应从一个称为新过程映像文件的常规可执行文件构建
。
成功的exec不会返回,因为
调用过程映像被新过程映像覆盖。
当这个调用执行C语言程序时,它就是
应作为C语言函数调用输入如下:
int main(int argc,char * argv []);
其中argc是参数count,argv是一个字符数组
指向参数本身的指针。另外,以下
变量:
extern char ** environ;
初始化为指向数组的指针字符指针
环境字符串。 argv和environ数组都是由空指针终止的
。终止argv
数组的空指针不计入argc。
-
任何足够高级的错误都与功能无法区分。< br $>
- Rich Kulawiec
The presence of the third argument with environment variable
information is a common Unix extension -- but it isn''t even
part of the Unix specification (which imports the POSIX.1
specification):
http://www.opengroup.org/onlinepubs/...ions/exec.html
The exec family of functions shall replace the current process
image with a new process image. The new image shall be constructed
from a regular, executable file called the new process image file.
There shall be no return from a successful exec, because the
calling process image is overlaid by the new process image.
When a C-language program is executed as a result of this call, it
shall be entered as a C-language function call as follows:
int main (int argc, char *argv[]);
where argc is the argument count and argv is an array of character
pointers to the arguments themselves. In addition, the following
variable:
extern char **environ;
is initialized as a pointer to an array of character pointers to
the environment strings. The argv and environ arrays are each
terminated by a null pointer. The null pointer terminating the argv
array is not counted in argc.
--
Any sufficiently advanced bug is indistinguishable from a feature.
-- Rich Kulawiec
这篇关于c标准中存在哪些主要声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!