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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:56:13+00:00 2026-05-28T03:56:13+00:00

For the last day I have had a nasty bug in my code which

  • 0

For the last day I have had a nasty bug in my code which after some searching appears to be related to comparison between char values and hex. My compiler is gcc 4.4.1 running on Windows.
I replicated the problem in the simple code below:

char c1 = 0xFF; char c2 = 0xFE;
if(c1 == 0xFF && c2 == 0xFE)
{
    //do something
}

Surprisingly the code above does not get in the loop. I have absolutely no idea why and would really appreciate some help on this. It is so absurd that the solution must be (as always) a huge mistake on my part that I totally overlooked.

If I replace the above with unsigned chars it works, but only in some cases. I am struggling to find out what’s going on. In addition if I cast the hex values to char in comparison it enters the loop correctly like so:

if(c1 == (char)0xFF && c2 == (char)0xFE)
{
    //do something
}

What does that mean? Why can it be happening? Isn’t the raw hex value interpreted as a char by default?
For the curious the point in my code where I first noticed it is comparison of first 2 bytes of a stream with the above hex value and their reverse to idenity the Byte Order Mark.

Any help is appreciated

  • 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-28T03:56:14+00:00Added an answer on May 28, 2026 at 3:56 am

    Plain char can be signed or unsigned. If the type is unsigned, then all works as you’d expect.
    If the type is signed, then assigning 0xFF to c1 means that the value will be promoted to -1 when the comparison is executed, but the 0xFF is a regular positive integer, so the comparison of -1 == 0xFF fails.

    Note that the types char, signed char and unsigned char are distinct, but two of them have the same representation (and one of the two is char).

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

Sidebar

Related Questions

We tried last night to build some code which would create a new public
I have had this problem for the last day. I have created a SOAP
Last day I have been interviewed and the interviewer asked me a) what is
i have to get the last day of the current month. how can i
I'm facing a problem I have never had before. The other day when I
I have been trying to debug my code whenever I had free-time for the
I have an FLA done in Flash 10, and some AS3 code that manipulates
In my last question I posted some sample code on how I was trying
I've asked several questions on Silverlight the last day or two (I have no
well i have used the facebook api couple of times. But last day i

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.