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

  • Home
  • SEARCH
  • 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 6171981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:18:54+00:00 2026-05-23T23:18:54+00:00

here is the question: in the Book ‘Computer Systems: A Programmer’s Perspective’ section 2.2.5

  • 0

here is the question:

in the Book ‘Computer Systems: A Programmer’s Perspective’ section 2.2.5

it said that if an unsigned value is comparing with a signed value, all values will be compared in the unisnged format. like this

if(-1 < 0u)
{
    // will not print this line because -1 will be translated to 255.
    printf("all changed to unsigned format");
}

I tried this code in VC6 SP6, the string was NOT outputed. And everything looks good because we all know that -1 was translated to 255.

but when I read the book ‘Expert C Programming Deep C Secrets’ section 1.10

It said that if my complier uses the ANSI C Standard, this code will print “-1 < (unsigned char)1: ANSI”:

if(-1 < (unsigned char)1)
{
    printf("-1 < (unsigned char)1: ANSI");
}
else
{
    printf("-1 NOT Less than (unsigned char)1: K&R");    
}

The output I got was: -1 < (unsigned char)1: ANSI.

I’m using the VC6 SP6 complier.

and why is this happening?

according to the book ‘Computer Systems: A Programmer’s Perspective’

-1 < (unsigned char)1 will make -1 be translated as an unsigned value. so it will become sth like this:

255 < 1

and this should not print out the line -1 < (unsigned char)1: ANSI.

can anybody tell me why this is happening?

  • 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-05-23T23:18:54+00:00Added an answer on May 23, 2026 at 11:18 pm

    if(-1 < (unsigned char)1)

    In this case both operands are promoted to int.

    if( -1 < 0u )

    In this case both operands are converted to unsigned int.

    The following quotes prove me right.

    Many binary operators that expect operands of arithmetic or
    enumeration type cause conversions and yield result types in a similar
    way. The purpose is to yield a common type, which is also the type of
    the result. This pattern is called the usual arithmetic conversions,
    which are defined as follows:
    — If either operand is of type long
    double, the other shall be converted to long double.
    — Otherwise, if
    either operand is double, the other shall be converted to double.
    —
    Otherwise, if either operand is float, the other shall be converted to
    float.
    — Otherwise, the integral promotions (4.5) shall be performed
    on both operands.54)
    — Then, if either operand is unsigned long the
    other shall be converted to unsigned long.
    — Otherwise, if one operand
    is a long int and the other unsigned int, then if a long int can
    represent all the values of an unsigned int, the unsigned int shall be
    converted to a long int; otherwise both operands shall be converted to
    unsigned long int.
    — Otherwise, if either operand is long, the other
    shall be converted to long.
    — Otherwise, if either operand is
    unsigned, the other shall be converted to unsigned. [Note: otherwise,
    the only remaining case is that both operands are int ]

    And this (integral promotions):

    An rvalue of type char, signed char, unsigned char, short int, or
    unsigned short int can be converted to an rvalue of type int if int
    can represent all the values of the source type; otherwise, the source
    rvalue can be converted to an rvalue of type unsigned int.

    To be perfectly honest, the quotes are from the C++03 standard, but they hold for C as well.

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

Sidebar

Related Questions

Here's a sort of odd question. I'm in the process of writing a book
first question here. I'm developing a program in C# (.NET 3.5) that displays files
C# question here.. I have a UTF-8 string that is being interpreted by a
First question here: it is a very short yet fundamental thing in Java that
I'm reading a algorithm book in my lesure time. Here is a question I
I have this question in my text book: Suppose that we have a set
Simple question here: is there any way to convert from a jagged array to
Newbie question here. I'm in the beginning stages of laying out a site in
The question here is whether something like this already exists or, if not, whether
First question here so hello everyone. The requirement I'm working on is a small

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.