Re: Regarding system function



"sunil" <sunil.vvn@xxxxxxxxx> wrote:

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

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

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.

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)is the system funcion is static

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

3) is the shell had executed that system command

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

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.

In case of any queries please revert me back.

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
.