473,394 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

conforming implementation?

If the concept of file streams is not possible to be implemented, can
all FILE related functions be "disabled"?
For example:

size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE
*stream) {
errno = something;
return 0;
}

Perhaps to generalize the question: When the behavior (or return
value) of a function is unspecified by the standard, can an
implementation always choose one behavior?

All replies appreciated.
Jun 27 '08 #1
9 1266
vi******@gmail.com wrote:
When the behavior (or return value)
of a function is unspecified by the standard,
can an implementation always choose one behavior?
It's allowed.

void *malloc(size_t size)
{
return NULL;
}

--
pete
Jun 27 '08 #2
On Sun, 18 May 2008 02:21:05 -0700 (PDT), vi******@gmail.com wrote in
comp.lang.c:
If the concept of file streams is not possible to be implemented, can
all FILE related functions be "disabled"?
Define a situation where it is "not possible" to implement these
streams.
For example:

size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE
*stream) {
errno = something;
return 0;
}

Perhaps to generalize the question: When the behavior (or return
value) of a function is unspecified by the standard, can an
implementation always choose one behavior?

All replies appreciated.
There are two types of possible conforming implementations, hosted and
free standing. A hosted environment must begin execution of a
program with three FILE streams already open, which can be referred to
by the macros stdin, stdout, and stderr. All the appropriate FILE
functions must be available on these streams.

A free standing environment, on the other hand, is not even required
to provide <stdio.hor file streams at all.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Jun 27 '08 #3
Jack Klein <ja*******@spamcop.netwrites:
[...]
There are two types of possible conforming implementations, hosted and
free standing. A hosted environment must begin execution of a
program with three FILE streams already open, which can be referred to
by the macros stdin, stdout, and stderr. All the appropriate FILE
functions must be available on these streams.
Yes, but those functions aren't necessarily required to succeed. For
example (using Unix shell syntax), given:

./my_program < /dev/null \
/this_disk_is_full/out \
2/this_disk_is_full/err

any attempt to read from stdin or write to stdout or stderr will fail.
I'm not convinced that a hosted implementation in which stdin, stdout,
and stderr are *always* unusable would be non-conforming.

The standard is written to allow for conforming implementations on a
wide variety of systems. One consequence of this is that it doesn't
require a conforming implementation to be *useful* (how could it?).
A free standing environment, on the other hand, is not even required
to provide <stdio.hor file streams at all.
Right.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #4
Keith Thompson wrote:
Jack Klein <ja*******@spamcop.netwrites:
[...]
There are two types of possible conforming implementations,
hosted and free standing. A hosted environment must begin
execution of a program with three FILE streams already open,
which can be referred to by the macros stdin, stdout, and
stderr. All the appropriate FILE functions must be
available on these streams.

Yes, but those functions aren't necessarily required to
succeed. For example (using Unix shell syntax), given:

./my_program < /dev/null \
/this_disk_is_full/out \
2/this_disk_is_full/err

any attempt to read from stdin or write to stdout or stderr
will fail. I'm not convinced that a hosted implementation in
which stdin, stdout, and stderr are *always* unusable would
be non-conforming.
I would argue that the user who typed the command has
chosen to run the program on a non-conforming implementation.

--
Peter
Jun 27 '08 #5
On May 18, 4:21*am, vipps...@gmail.com wrote:
If the concept of file streams is not possible to be implemented, can
all FILE related functions be "disabled"?

I suspect it would be confirming, although not all that useful, if a
hosted implementation failed all fopens, immediately returned EOF for
stdin, and bit-bucketed any writes to stdout and strerr.
Jun 27 '08 #6
Peter Nilsson <ai***@acay.com.auwrites:
Keith Thompson wrote:
>Jack Klein <ja*******@spamcop.netwrites:
[...]
There are two types of possible conforming implementations,
hosted and free standing. A hosted environment must begin
execution of a program with three FILE streams already open,
which can be referred to by the macros stdin, stdout, and
stderr. All the appropriate FILE functions must be
available on these streams.

Yes, but those functions aren't necessarily required to
succeed. For example (using Unix shell syntax), given:

./my_program < /dev/null \
> /this_disk_is_full/out \
2/this_disk_is_full/err

any attempt to read from stdin or write to stdout or stderr
will fail. I'm not convinced that a hosted implementation in
which stdin, stdout, and stderr are *always* unusable would
be non-conforming.

I would argue that the user who typed the command has
chosen to run the program on a non-conforming implementation.
An interesting thought, but I disagree. After all, the various I/O
functions are designed to detect errors for a reason.

If I write to stdout and the disk fills up after I've written a
gigabyte of data, and the implementation correctly tells me about the
error, that's not non-conforming. Same thing if it fills up after I
write a megabyte of data. Or a kilobyte. Or none.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #7
Keith Thompson wrote:
Jack Klein <ja*******@spamcop.netwrites:
[...]
>There are two types of possible conforming implementations, hosted and
free standing. A hosted environment must begin execution of a
program with three FILE streams already open, which can be referred to
by the macros stdin, stdout, and stderr. All the appropriate FILE
functions must be available on these streams.

Yes, but those functions aren't necessarily required to succeed. For
example (using Unix shell syntax), given:

./my_program < /dev/null \
/this_disk_is_full/out \
2/this_disk_is_full/err

any attempt to read from stdin or write to stdout or stderr will fail.
I'm not convinced that a hosted implementation in which stdin, stdout,
and stderr are *always* unusable would be non-conforming.
I don't agree. A read from /dev/null doesn't /*fail*/, but rather
returns EOF:
cat readnull.c
#include <stdio.h>

int main(void)
{
char buf[80];

if(!fgets(buf, sizeof(buf), stdin)){
if(feof(stdin))
printf("EOF\n");
else if(ferror(stdin))
printf("ERROR\n");
else
printf("?\n");

}

return (0);
}
./readnull < /dev/null
EOF

--
Pietro Cerutti
Jun 27 '08 #8
Pietro Cerutti <ga**@gahr.chwrites:
Keith Thompson wrote:
>Jack Klein <ja*******@spamcop.netwrites:
[...]
>>There are two types of possible conforming implementations, hosted and
free standing. A hosted environment must begin execution of a
program with three FILE streams already open, which can be referred to
by the macros stdin, stdout, and stderr. All the appropriate FILE
functions must be available on these streams.
Yes, but those functions aren't necessarily required to succeed. For
example (using Unix shell syntax), given:
./my_program < /dev/null \
> /this_disk_is_full/out \
2/this_disk_is_full/err
any attempt to read from stdin or write to stdout or stderr will
fail.
I'm not convinced that a hosted implementation in which stdin, stdout,
and stderr are *always* unusable would be non-conforming.

I don't agree. A read from /dev/null doesn't /*fail*/, but rather
returns EOF:
[snip]

Good point.

It's difficult to construct a good example of what I'm trying to do,
since if the file is unreadable the error will generally be caught by
the shell before the program is invoked. (Again, I'm using a
Unix-specific example to illustrate a more general point.)

Replace /dev/null with some file or device that can be opened for
reading but on which any read attempts will actually fail and set the
error flag for the stream. I'm still not convinced that this would be
non-conforming. To demonstrate that it *is* non-conforming, you'd
have to find wording in the standard that says it must be possible to
read from stdin without error. It may be ambiguous, but I don't think
there's a clear statement to that effect.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #9
Keith Thompson wrote:
Pietro Cerutti <ga**@gahr.chwrites:
>Keith Thompson wrote:
>>Jack Klein <ja*******@spamcop.netwrites:
[...]
There are two types of possible conforming implementations, hosted and
free standing. A hosted environment must begin execution of a
program with three FILE streams already open, which can be referred to
by the macros stdin, stdout, and stderr. All the appropriate FILE
functions must be available on these streams.
Yes, but those functions aren't necessarily required to succeed. For
example (using Unix shell syntax), given:
./my_program < /dev/null \
/this_disk_is_full/out \
2/this_disk_is_full/err
any attempt to read from stdin or write to stdout or stderr will
fail.
I'm not convinced that a hosted implementation in which stdin, stdout,
and stderr are *always* unusable would be non-conforming.
I don't agree. A read from /dev/null doesn't /*fail*/, but rather
returns EOF:
[snip]

Good point.

It's difficult to construct a good example of what I'm trying to do,
since if the file is unreadable the error will generally be caught by
the shell before the program is invoked. (Again, I'm using a
Unix-specific example to illustrate a more general point.)

Replace /dev/null with some file or device that can be opened for
reading but on which any read attempts will actually fail and set the
error flag for the stream. I'm still not convinced that this would be
non-conforming. To demonstrate that it *is* non-conforming, you'd
have to find wording in the standard that says it must be possible to
read from stdin without error. It may be ambiguous, but I don't think
there's a clear statement to that effect.
The standard doesn't say much about std[in|out|err]...
Thus, I would argue that the lake of explicit requisites on these three
FILE*s guarantees an implementation not providing successful I/O to be
still conforming.

--
Pietro Cerutti
Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: ik | last post by:
Hello All, Can somebody tell, which compiler conforms C++ Standard, regarding templates better on Win32 Platform ? I was finding problems with VC++6.0 with some template code, but the same works...
82
by: Buford Early | last post by:
I read this in http://annevankesteren.nl/2004/12/xhtml-notes "A common misconception is that XHTML 1.1 is the latest version of the XHTML series. And although it was released a bit more than a...
5
by: Scorpio | last post by:
Hi, I have made a list of C99 conforming compilers at http://geocities.com/avsharath/c99compilers.htm I've created this list by searching the web thoroughly. Please let me know if you are aware...
2
by: Peter Rooney | last post by:
hi all, i'm working on a project where i'm marshalling xml files to java objects created with JAXB 1.0 from an xsd schema. the problem is that the marshalling fails (UnexpectedElementException)...
351
by: CBFalconer | last post by:
We often find hidden, and totally unnecessary, assumptions being made in code. The following leans heavily on one particular example, which happens to be in C. However similar things can (and...
3
by: ais523 | last post by:
Consider the following program: #include <stdlib.h> #include <limits.h> int main(void) { size_t s=SIZE_MAX; size_t i; char* p;
32
by: r.z. | last post by:
class vector3 { public: union { float data; struct { float x, y, z; };
9
by: borophyll | last post by:
GCC allows you to define macros called "new" and "delete" in the preprocessor phase. This seems to be in violation of the C++ spec, in particular the rules for the creation of preprocessing...
6
by: Kai-Uwe Bux | last post by:
Juha Nieminen wrote: I think your code violates the One-Definition-Rule. The template function foo() is defined in two significantly different ways in the two files. As far as I know, no...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.