关于系统功能 [英] Regarding system function

查看:66
本文介绍了关于系统功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


请看下面的程序


#include< stdlib.h>

int i = system(" pwd");


我在UNIX中编译了上面的程序,它被编译了并且执行了没有任何错误的
它打印出目前的工作目录。对于这个程序有一定的疑问。


1)没有主要如何执行

2)是系统功能是静态的

3)是shell执行了那个系统命令


如果我写简单的话

#include< stdlib.h>

system(" pwd")

编译阶段的两个错误


4)返回类型如何扮演一个角色,是否强制要求

来收集C中的返回类型(据我所知,它不是强制性的

收集返回类型)。


如有任何疑问,请将我还原。


问候

Sunil

Hi All,

Please have a look the below program

#include<stdlib.h>
int i = system("pwd");

I compiled the above program in UNIX ,it got compiled and
executed with out any errors.It prints the present working directory.Am
having certain doubts about this program.

1) without main how it got executed
2)is the system funcion is static
3) is the shell had executed that system command

if i write simply
#include<stdlib.h>
system("pwd")
it''s thwoing errors at compilation stage

4) how return type is playing a role,is it mandatory
to collect the return type in C(upto my knowledge it''s not mandatory to
collect the return type).

In case of any queries please revert me back.

Regards
Sunil

推荐答案

" sunil" < su ******* @ gmail.comwrote:
"sunil" <su*******@gmail.comwrote:

#include< stdlib.h>

int i = system (pwd);


我在UNIX中编译了上面的程序,它被编译并执行了没有任何错误的

#include<stdlib.h>
int i = system("pwd");

I compiled the above program in UNIX ,it got compiled and
executed with out any errors.



那么,那是错的。是时候在你的

编辑中加上警告级别,或者停止编译GNU几乎 - 但不是很完全C。


来自标准,第6.7.8段,第4项:具有静态存储持续时间的对象的

初始化程序中的所有表达式应为

常量表达式或字符串文字。函数调用不是

常量表达式或字符串文字;因此,此代码不是正确的C.

Well, that''s wrong, then. Time to hitch up the warning level on your
compilations, or to stop compiling GNU almost-but-not-quite-C.

From the Standard, paragraph 6.7.8, item 4: "All the expressions in an
initializer for an object that has static storage duration shall be
constant expressions or string literals". A function call is not a
constant expression or a string literal; therefore, this code is not
correct C.


它打印当前的工作目录.Am

有关于这个程序的某些疑问。


1)没有主要如何执行
It prints the present working directory.Am
having certain doubts about this program.

1) without main how it got executed



它不应该是。

It shouldn''t have been.


2)系统功能是静态的
2)is the system funcion is static



这没有意义。对象可以有静态持续时间;函数

只是_are_。

That does not make sense. Objects can have static duration; functions
just _are_.


3)是shell执行了系统命令
3) is the shell had executed that system command



嗯,是的,当然。毕竟这就是system()的用途。

Well, yes, of course. That''s what system() is for, after all.


4)返回类型如何扮演角色,是强制性的

收集C中的返回类型(据我所知,它不是强制性的,因为
收集返回类型)。
4) how return type is playing a role,is it mandatory
to collect the return type in C(upto my knowledge it''s not mandatory to
collect the return type).



No.

No.


如有任何疑问,请将我还原。
In case of any queries please revert me back.



Yer_what_? 请让我回来?好吧,如果你这样说......如果有人

发送一个查询我会抛弃你今天的版本然后回到

备份你昨天做了。


Richard

Yer_what_? "Please revert me back"? Ok, if you say so... If someone
sends in a query I''ll ditch today''s version of you and go back to the
backup you made yesterday.

Richard


Richard Bos写道:
Richard Bos wrote:

sunil < su ******* @ gmail.comwrote:

"sunil" <su*******@gmail.comwrote:


>> #include< stdlib.h>
int i = system(pwd);

我在UNIX中编译了上面的程序,它被编译并执行时没有任何错误。
>>#include<stdlib.h>
int i = system("pwd");

I compiled the above program in UNIX ,it got compiled and
executed with out any errors.




那么,那是错的。是时候在你的

编辑中加上警告级别,或者停止编译GNU几乎 - 但不是很完全C。


来自标准,第6.7.8段,第4项:具有静态存储持续时间的对象的

初始化程序中的所有表达式应为

常量表达式或字符串文字。函数调用不是

常量表达式或字符串文字;因此,此代码不是正确的C.



Well, that''s wrong, then. Time to hitch up the warning level on your
compilations, or to stop compiling GNU almost-but-not-quite-C.

From the Standard, paragraph 6.7.8, item 4: "All the expressions in an
initializer for an object that has static storage duration shall be
constant expressions or string literals". A function call is not a
constant expression or a string literal; therefore, this code is not
correct C.


>>它打印当前的工作目录.Am <对这个程序有一定的疑虑。

1)没有主要如何执行
>>It prints the present working directory.Am
having certain doubts about this program.

1) without main how it got executed




它不应该''已经过了。



It shouldn''t have been.


> 2)系统功能是静态的
> 2)is the system funcion is static




这没有意义。对象可以有静态持续时间;功能

只是_are_。



That does not make sense. Objects can have static duration; functions
just _are_.


> 3)是shell执行了系统命令
> 3) is the shell had executed that system command




嗯,是的,当然。毕竟这就是system()的用途。



Well, yes, of course. That''s what system() is for, after all.


> 4)返回类型如何发挥作用,是否必须在C中收集返回类型(据我所知,它不是强制收集返回类型)。
> 4) how return type is playing a role,is it mandatory
to collect the return type in C(upto my knowledge it''s not mandatory to
collect the return type).




No.



No.


>>如有的话查询请将我还原。
>>In case of any queries please revert me back.




Yer_what_? 请让我回来?好吧,如果你这样说......如果有人

发送一个查询我会抛弃你今天的版本然后回到

备份你昨天做了。


Richard



Yer_what_? "Please revert me back"? Ok, if you say so... If someone
sends in a query I''ll ditch today''s version of you and go back to the
backup you made yesterday.

Richard



更神秘的是函数调用pwd。


但这将是COMPILER所在的pwd,因为

编译器调用pwd。由于糟糕的程序甚至尚未编译,因此它不会是程序所在的目录


What is more mysterious is that the function calls "pwd".

But this will be the pwd where the COMPILER is, since the
compiler calls "pwd". It will NOT be the directory where
the program will be since the poor program is not even compiled yet!




Richard Bos < rl*@hoekstra-uitgeverij.nlwrote in message

news:45 *************** @ news.xs4all.nl ...

"Richard Bos" <rl*@hoekstra-uitgeverij.nlwrote in message
news:45***************@news.xs4all.nl...

" sunil" < su ******* @ gmail.comwrote:
"sunil" <su*******@gmail.comwrote:

#include< stdlib.h>

int i = system (pwd);


我在UNIX中编译了上面的程序,它被编译并执行了没有任何错误的

#include<stdlib.h>
int i = system("pwd");

I compiled the above program in UNIX ,it got compiled and
executed with out any errors.



那么,那是错的。是时候在你的

编辑中加上警告级别,或者停止编译GNU几乎 - 但不是很完全C。


Well, that''s wrong, then. Time to hitch up the warning level on your
compilations, or to stop compiling GNU almost-but-not-quite-C.



没有理由选择海湾合作委员会。我正在使用的非常旧版本的GCC会给出一个

警告,并且无法编译_without_任何额外选项,例如''-Wall''或

'' -pedantic''。

Rod Pemberton

No reason to pick on GCC. The very old version of GCC I''m using, gives a
warning and fails to compiler _without_ any extra options such as ''-Wall'' or
''-pedantic''.
Rod Pemberton


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

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