Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8592687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:48:35+00:00 2026-06-11T23:48:35+00:00

I have read through the C11 standard, section 7.21 where <stdio.h> is described. The

  • 0

I have read through the C11 standard, section 7.21 where <stdio.h> is described. The standard first describes streams as:

7.21.2.2:

A text stream is an ordered sequence of characters …

7.21.2.3:

A binary stream is an ordered sequence of characters …

Which doesn’t specify the type of the stream characters (since this depends on orientation). It later says:

7.21.3.12:

… The byte output functions write characters to the stream as if by successive calls to the fputc function.

From fputc (7.21.7.3.2):

The fputc function writes the character specified by c (converted to an unsigned char) to the output stream pointed to by stream …

Which indicates the int c argument of fputc is converted to an unsigned char before being written to the stream. A similar note is given for fgetc:

7.21.7.1.2:

the fgetc function obtains that character as an unsigned char converted to an int

and ungetc, fread and fwrite.

Now this all hints that internally, a byte oriented stream is represented by unsigned chars.

However, looking at the internals of the Linux kernel, it seems like files are considered to be streams of char. One reason I am saying this is that the file_operations read and write callbacks get char __user * and const char __user * respectively.

In the implementation of glibc, FILE is a typedef of struct _IO_FILE which is defined in libio/libio.h. In this struct also, all read and write pointers are char *.

In C++, the basic_ostream::write function takes const char * as input and similarly basic_istream::read (but I’m not interested in C++ in this question).

My question is, do the quotes above imply that FILE streams should be threated as streams of unsigned char? If so, why does the glibc and the Linux kernel implement them with char *? If not, why does the standard insist on converting the characters to unsigned char?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:48:36+00:00Added an answer on June 11, 2026 at 11:48 pm

    It doesn’t really matter. The standard use unsigned char at some chosen place because it allows precise formulation at those places:

    • fgetc is specified to return a unsigned char converted to an int so that one knows that the result is positive or null excepted when it is EOF (and thus there is no confusion possible between EOF and a valid char, confusion which is cause of bugs when one store directly the result of fgetc in a char without checking for EOF beforehand).

    • fputc is specified to take an int and convert it to an unsigned char because this conversion is well specified. If you aren’t careful, formulation not using unsigned char could make UB a sequence like

      int c = fgetc(stdin);
      if (c != EOF)
          fputc(c, stdout);
      

    with signed char for negative chars.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to have my application read through a text file and look for
First off, I have read through a list of postings on this topic and
First of all, I have read through many S.O. questions regarding this topic and
I have read through the follow SO articles C#: How do I call a
I have read through several articles which are alternatives to using setpixel/getpixel but I
I have read through the Rails docs for Routing , Restful Resources , and
I have read through some tutorials about javascript prototypal inheritance patterns but I am
Okay guys, I have read through all the other posts and question on jQuery
This is probably not a dup; I have read through many similar problems on
Ok, I'm programming in objective-C and using Xcode. I have read through the documentation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.