Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is possible for an implementation to meet the interface requirements for <code>fgetc</code> and <code>fputc</code> even if <code>sizeof(int) == 1</code>.</p> <p>The interface for <code>fgetc</code> says that it returns the character read as an <code>unsigned char</code> converted to an <code>int</code>. Nowhere does it say that this value cannot be <code>EOF</code> even though the expectation is clearly that valid reads "usually" return positive values. Of course, <code>fgetc</code> returns <code>EOF</code> on a read failure or end of stream but in these cases the file's error indicator or end-of-file indicator (respectively) is also set.</p> <p>Similarly, nowhere does it say that you can't pass <code>EOF</code> to <code>fputc</code> so long as that happens to coincide with the value of an <code>unsigned char</code> converted to an <code>int</code>.</p> <p>Obviously the programmer has to be very careful on such platforms. This is might not do a full copy:</p> <pre><code>void Copy(FILE *out, FILE *in) { int c; while((c = fgetc(in)) != EOF) fputc(c, out); } </code></pre> <p>Instead, you would have to do something like (not tested!):</p> <pre><code>void Copy(FILE *out, FILE *in) { int c; while((c = fgetc(in)) != EOF || (!feof(in) &amp;&amp; !ferror(in))) fputc(c, out); } </code></pre> <p>Of course, platforms where you will have real problems are those where <code>sizeof(int) == 1</code> and the conversion from <code>unsigned char</code> to <code>int</code> is not an injection. I believe that this would necessarily the case on platforms using sign and magnitude or ones complement for representation of signed integers.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload