基础建设 [英] elementary construction

查看:48
本文介绍了基础建设的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天是我在唱诗班唱歌的时候,当我意识到为了进入C唱诗班,我不得不购买K& R时,我正在考虑排练

>
阅读相同的音乐。


我熟悉 http://www.eskimo.com/~scs/C-faq/top.html ,但我找到了

无法解决我的第一个问题,这个问题出现在第6页。我总是用
调用main来表示有多少指针被传递给

它。这只是风格问题吗?


int main(int a,int b,int c){return(51);}是,接近

琐碎,符合ANSI标准? MPJ

Today is when I sing in the choir, and I was thinking about rehearsal
tonight when I realized that in order to be in the C choir, I had to buy K&R
to be reading the same "music."

I am familiar with http://www.eskimo.com/~scs/C-faq/top.html , but I found
no resolution to my first question, which crops up on page 6. I have always
called main with an integer that says how many pointers are being passed to
it. Is this just a matter of style?

Would int main(int a, int b, int c){ return (51);} be, while close to
trivial, ANSI compliant? MPJ

推荐答案

Merrill& Michele< be ******** @ comcast.net>潦草地写着以下内容:
Merrill & Michele <be********@comcast.net> scribbled the following:
今天是我在唱诗班唱歌的时候,我正在考虑排练今晚当我意识到为了进入C唱诗班时,我不得不购买K& ; R
要阅读相同的音乐。
我熟悉 http:// www .eskimo.com / ~scs / C-faq / top.html ,但我发现
没有解决我的第一个问题,这个问题出现在第6页。我总是把它称为main用一个整数表示将多少指针传递给
它。这只是风格问题吗?


main的第一个参数应该是一个整数,表示

参数的数量,第二个参数应该是参数本身的指针。

这不是风格问题,而是标准要求。

int main(int a,int b,int c){return(51);}是,虽然接近
琐碎,ANSI兼容? MPJ
Today is when I sing in the choir, and I was thinking about rehearsal
tonight when I realized that in order to be in the C choir, I had to buy K&R
to be reading the same "music." I am familiar with http://www.eskimo.com/~scs/C-faq/top.html , but I found
no resolution to my first question, which crops up on page 6. I have always
called main with an integer that says how many pointers are being passed to
it. Is this just a matter of style?
The first argument to main should be an integer saying the number of
arguments, the second should be a pointer to the arguments themselves.
It''s not a matter of style, it''s the standard requirement.
Would int main(int a, int b, int c){ return (51);} be, while close to
trivial, ANSI compliant? MPJ




不,不会。


-

/ - Joona Palaste( pa*****@cc.helsinki.fi)-------------芬兰-------- \

\-- < a rel =nofollowhref =http://www.helsinki.fi/~palastetarget =_ blank> http://www.helsinki.fi/~palaste ------ ---------------规则! -------- /

人类中的孤雌生殖将导致建立一个新的宗教信仰。

- John Nordberg



No it would not.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Parthenogenetic procreation in humans will result in the founding of a new
religion."
- John Nordberg


Merrill& Michele< be ******** @ comcast.net>写道:
Merrill & Michele <be********@comcast.net> wrote:
我熟悉 http://www.eskimo.com/~scs/C-faq/top.html ,但我发现没有解决我的第一个问题,这个问题出现在第6页。我总是
用一个整数调用main,表示有多少指针被传递给
它。这只是风格问题吗?
int main(int a,int b,int c){return(51);}是否,虽然接近
琐碎,但ANSI兼容? MPJ
I am familiar with http://www.eskimo.com/~scs/C-faq/top.html , but I found
no resolution to my first question, which crops up on page 6. I have always
called main with an integer that says how many pointers are being passed to
it. Is this just a matter of style? Would int main(int a, int b, int c){ return (51);} be, while close to
trivial, ANSI compliant? MPJ




编号标准祝福的唯一版本的main()是

没有传递任何东西,即


int main(void)


或传递一个int和一个char指针数组


int main(int argc,char * argv [])


你有时也会发现它是写的


int main(int argc,char ** argv)


,argv有argc + 1个元素,argv [0]到argv [argc-1]指向

到字符串,argv [argc]是null指针。当然,如果你想要混淆阅读你程序的人,你可以给argc和

argv不同的名字 - 为了最大限度地交换他们的名字;-)


问候,Jens

-

\ Jens Thoms Toerring ___ Je *********** @ physik.fu-berlin.de

\ __________________________ < a rel =nofollowhref =http://www.toerring.detarget =_ blank> http://www.toerring.de


Merrill& Michele写道:
Merrill & Michele wrote:
今天是我在唱诗班唱歌的时候,我正在考虑排练今晚当我意识到为了进入C唱诗班时,我不得不购买K& R
要读相同的音乐。

我熟悉 http://www.eskimo.com/~scs/C-faq/top.html ,但我发现
没有解决方案我的第一个问题,在第6页出现。我总是用一个整数调用main来说明有多少指针被传递给
它。这只是一种风格问题吗?

int main(int a,int b,int c){return(51);}是否会接近
琐事,ANSI兼容? MPJ
Today is when I sing in the choir, and I was thinking about rehearsal
tonight when I realized that in order to be in the C choir, I had to buy K&R
to be reading the same "music."

I am familiar with http://www.eskimo.com/~scs/C-faq/top.html , but I found
no resolution to my first question, which crops up on page 6. I have always
called main with an integer that says how many pointers are being passed to
it. Is this just a matter of style?

Would int main(int a, int b, int c){ return (51);} be, while close to
trivial, ANSI compliant? MPJ




不在托管环境中它涵盖了大多数通用C实现的大部分内容。这样一个
实现通过处理一些必要的内务管理来启动一个程序(例如,初始化所有

你的'静态'变量,设置stdin / out / err,然后是

等等,然后调用main()函数,你需要提供
。实现使用Implementation Magic(tm)

来完成所有这些,但是没有足够的神奇来阅读

你想知道你的main()想要什么样的参数,

所以它总是提供一个'int''和一个`char **''。如果你的

main()期望别的东西,那就会出现不可预知的混乱




其实还有一点魔术:你可以

写你的main()以期望没有任何参数,并且无论如何都需要

实现来调用它。因此,

是两个有效的签名。 for main():


int main(int,char **);

int main(void);


(当然,有其他方式来表达这两种可能性。)


现在,特定的C实现也可能支持

其他main()签名除了两个必需的

之外的语言 - 一个常见的扩展名是


int main(int ,char **,char **);


其中第三个(非标准)参数指向一个环境变量的

数组。 ;标准没有

禁止使用main()这样的替代形式,但也没有
要求它们。如果您的平台

支持它们,您可以使用其他表格,但是当您将

代码移至其他平台时,所有投注均已关闭。


所有这些都与托管环境有关。 C

标准还考虑了独立环境,

种C实现可以操作你的微波炉

烤箱或你的会说话的厕所。 (我不是在开玩笑;使用谷歌。)

这些环境自己调用

和终止程序,而main()可能有一个完全

不同形式 - 它甚至可能没有任何特殊含义

。实际上,可能没有程序

start这样的概念。或程序结束;只要电流不断流动,程序就可以简单地运行




最后,关于所有实施魔法(tm)的说法。

我已经说过调用main(),但事实上,main()开始执行的实际意义是

,不一定是真正的语言函数调用。实施必须使它成为b $ b出现好像 main()已从高阶

函数调用,但这种情况发生的方式可能是极其神秘的。你真的不必担心

这是因为一旦你的main()收到控制权,似乎已经以普通方式调用了
;我只是提到

这是为了让我的同伴远离我的情况。


回到你的音乐比喻,当你'由一个管风琴和/或钢琴和/或管弦乐队的合唱团主持



调整到A = 440Hz几乎是强制性的;你使用

标准表格为main()。一些对早期音乐感兴趣的团体可能故意使用A = 435Hz等较旧的调音;

某些平台支持其他主要()形式。当你在淋浴时唱歌时,Nessun dorma听起来很多

如果你将A降低到370Hz左右会更好;有一个独立式淋浴间的主()没有标准的




-
Er ********* @ sun.com



Not in a "hosted environment," which covers the vast
majority of general-purpose C implementations. Such an
implementation launches a program by taking care of some
necessary housekeeping (for example, initializing all
your `static'' variables, setting up stdin/out/err, and
so forth) and then calling the main() function that you
supply. The implementation uses Implementation Magic(tm)
to accomplish all this, but isn''t Magical enough to read
your mind about what sort of arguments your main() wants,
so it always provides an `int'' and a `char**''. If your
main() expects something else, unpredictable confusion
will arise.

Actually, there is one further bit of Magic: You can
write your main() to expect no arguments at all, and the
implementation is required to call it anyhow. Thus, there
are two valid "signatures" for main():

int main(int, char**);
int main(void);

(There are, of course, other ways to express these two
possibilities.)

Now, a particular C implementation may also support
other main() signatures in addition to the two required
by the language -- a common extension is

int main(int, char**, char**);

where the third (non-standard) argument points to an
array of "environment variables." The Standard does not
forbid such alternate forms for main(), but also does not
require them. You can use other forms if your platform
supports them, but all bets are off when you move your
code to a different platform.

All this pertains to "hosted environments." The C
Standard also considers "free-standing environments," the
sort of C implementation that might operate your microwave
oven or your talking toilet. (I''m not kidding; use Google.)
These environments make their own provisions for invoking
and terminating programs, and main() may have a completely
different form -- it may not even have any special meaning
at all. Indeed, there may be no such concept as "program
start" or "program finish;" the program may simply run as
long as the electricity keeps flowing.

Finally, a word about all that Implementation Magic(tm).
I''ve said it "calls main()," but in fact the actual means by
which main() begins to execute need not be a bona-fide C
language function call. The implementation must make it
appear "as if" main() has been called from a higher-order
function, but the means by which this happens could be
mysterious in the extreme. You really needn''t worry about
this because once your main() receives control it seems to
have been called in ordinary fashion; I''m only mentioning
this to keep my fellow pedants off my case.

To return to your music analogy, when you''re "hosted"
by a choir with an organ and/or piano and/or orchestra,
tuning to A = 440Hz is all but mandatory; you use the
standard forms for main(). Some groups with an interest in
early music may deliberately use older tunings like A=435Hz;
some platforms support alternate main() forms. And when
you''re singing in the shower, "Nessun dorma" sounds a lot
better if you slide that A down to 370Hz or so; there are
no standards for main() in a free-standing shower stall.

--
Er*********@sun.com


这篇关于基础建设的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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