W dniu poniedziałek, 19 listopada 2012 18:31:24 UTC+1 użytkownik James Kuyper napisał:
I would like to return whole string to system not just number (In general way maybe even any kind of data,
That's fine, but doesn't really answer my question - after you return
that string value, what do you want to have happen to it? If all you
want to do is return it, and you don't really care what happens to it
after it has been returned, you can achieve essentially the same result
in C by just typing:
exit("some string",0);
If you don't consider that an acceptable solution to your problem, that
means that you do care what happens to it after it has been returned,
and you should tell us what you want that to be.
However, in that case, you've got a serious problem: exit() marks the
beginning of the end of a C program; when it's done, "control returns to
the host environment". From that point onwards, the possibilities for
what can happen are determined by the host environment, and not by the C
standard.
The only thing the C standard requires is the ability to distinguish
successful and unsuccessful exit status. The committee decided on this
as a least-common denominator that would be implementable on almost
every known platform. If the host environment doesn't allow reporting an
exit status, a conforming implementation can simply ignore the argument
passed to exit(). On almost every system that does allow an exit status
to be reported, the distinction between unsuccessful and successful
results is sufficient. If, in some environment, more distinctions are
desired, the argument passed to exit() provides an interface that allows
such inherently unportable code to be written. If the host environment
requires more information than can be encoded in an 'int',
implementations of C targeting that environment would have to implement
an extension to C allowing the extra information to be reported.
Now, if you want to restrict your code to host environments which allow
the exit status to be a string, the current standard allows a fully
conforming implementation of C for such an environment to accept code
like the following:
exit((int)"some string");
This implies that 'int' must be big enough to reversibly store the
location of the string. If that would make 'int' too large to be useful
for other purposes, then an implementation targeting that environment
would have to provide some other method of specifying the string to be
returned. It also implies that if there is any char* pointer which
converts to an int value of 0, the string it points at (if any) must be
treated as having a successful exit status.
The key point is that the C standard is deliberately intended to be
implementable in a wide variety of host environments, including ones
which do NOT allow returning a string as an exit status. Therefore, if
you want the C standard to allow exit("some string"), it will need to
specify the required behavior of exit() in an implementation of C
targeted for such an environment. What do you think that specification
should be?
For reference, the current specification is:
"If the value of status is zero or EXIT_SUCCESS, an
implementation-defined form of the status successful termination is
returned. If the value of status is EXIT_FAILURE, an
implementation-defined form of the status unsuccessful termination is
returned. Otherwise the status returned is implementation-defined."
(7.22.4.4p5)
Any new specification will need to be backward compatible with the
current one, or it will have no chance of being accepted.
... I was sayin that few week ago,
here I just used it as an argument that clever
improvements ale welcome - so there is point
of inventing and also talking about them )
Well, since you brought it up, I'm using it as an example of how
seemingly "clever" "improvements" may have unforeseen consequences that
render them neither "clever", nor an "improvement".