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 8827755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:26:51+00:00 2026-06-14T07:26:51+00:00

I was reading the book Programming in C by Stephen G. Kochan about C

  • 0

I was reading the book Programming in C by Stephen G. Kochan about C programming. It states that:

“if a character value is used that is not part of the standard character, its sign might be extended when converted to an integer”

And then it states

“C language permits character variable to be declared unsigned, this avoiding this potential problem”

Can someone explain what problem may occur when extending the sign during conversion from char to int?
And why does this matter?
And what’s wrong with an negative integer which is converted form a char?

Thank You

  • 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-14T07:26:53+00:00Added an answer on June 14, 2026 at 7:26 am

    Let’s say you take an innocent looking function from <ctype.h>, isupper().

    It’s defined int isupper(int c);. So it takes an int and returns an int.

    Now, let’s say that you’re not a very careful programmer, and you just pass you char to this function. You think to yourself: “What could go wrong? This is the simplest function I know!”.

    But you’d be wrong. Somewhere, someone will have her MP3 player going into an endless crash-loop because of this terrible mistake.

    And here’s why. The most annoying type in C is char. It can be signed, it can be unsigned, you can force the compiler one way or another (but then you open another can of worms), and worst of all, the standard C library uses this type everywhere!

    So, you use char, but you’re not aware of the fact that it’s actually signed in your environment. You use it as if the world is an ASCII world.

    But the world isn’t. And that MP3 happy owner is now listening to a famous German song whose name contains the letter ä (“extended ASCII code 132”).

    You pass this character to isupper(), and the compiler does the following horror:
    “Ah, it’s a character, but the function takes an integer. I know! I will not warn the programmer, because that’s too simple. I’ll just convert the character to an integer and pass it along. How do I do that? Let’s check the C standard… Hmmm… Simple, just take the value and sign-extend it (because char is signed, don’t you know?). Now, this character has the value -124, so I’ll just convert it to an int with the value -124. That was simple, I don’t see what the fuss is about. Why should I even warn the programmer?!”

    And now isupper() is called with -124 instead of 132.

    But what’s wrong with that? Nothing, except that the C library that comes with the compiler implements isupper() using a simple 128-byte array: it simply returns the value at the given index. The array is initialised with 0 everywhere except for upper-case ASCII codes, where it’s 1. Such a simple and elegant implementation…

    But wait, what happens if you pass a negative value to this function? Well, that’s not allowed:

    The c argument is an int, the value of which the application shall
    ensure is a character representable as an unsigned char or equal to
    the value of the macro EOF. If the argument has any other value, the
    behavior is undefined.

    So, undefined behaviour. In this case, it tries to access memory that doesn’t belong to the process, and BAM! the program crashes.

    So you see, char is evil and you should never use it, unless you really understand how to use it properly.

    (*) As Keith Thompson said in the comment, it is of course impossible to avoid using char. From strlen() to curl_easy_escape(), everybody uses char. But you should be aware of conversions to int, especially when char may hold a negative number. <ctype.h> functions and array indices are two places where it’s easy to make costly mistakes.

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

Sidebar

Related Questions

I'm reading a book about parallel programming an it says that it's not thread
Hi, guys! Currently I'm reading a book Programming in Objective-C by Stephen Kochan. Actually
Reading a book about C# I noticed that sometimes is mentioned value type and
I'm reading a book called programming in objective-c by Stephen Kochan. I've been reading
im currently reading a book about programming Android and there is a nice little
I'm new to Java but not to programming. I'm reading the book Beginning Android
I am reading about iOS programming and I bought the Programming iOS 4 book.
I'm reading a book about programming ASP.NET in C#. The book makes the following
Am reading the book Objective-C Programming by Big Nerd Ranch, and am not sure
I'm reading a book about iOS (it calls Programming iOS 4, by Matt Neuburg)

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.