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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:10:37+00:00 2026-05-30T05:10:37+00:00

I have a problem where 2 different compilers (GCC and IAR) are dropping my

  • 0

I have a problem where 2 different compilers (GCC and IAR) are dropping my mask from an if of different sized variables.

I have the following code:

uint8_t Value2;
uint16_t WriteOffset;
bool Fail;

void test(void)
{
        uint8_t buff[100];
        uint16_t r;

        for(r=0;r<Value2+1;r++)
        {
                if(buff[r]!=(WriteOffset+r)&0xFF)
                {
                        Fail=true;
                }
        }
}

The if fails (goes into the {} block) when buff[r] ==0 and WriteOffset+r == 0x100.

GCC outputs the following assembly:

movzwl -0xc(%ebp),%eax                          ; Load 'r'->EAX
mov    -0x70(%ebp,%eax,1),%al                   ; Load 'buff[r]'->AL
movzbl %al,%edx                                 ; Move AL to (unsigned int)EDX
mov    0x4b19e0,%ax                             ; Load 'WriteOffset'->AX
movzwl %ax,%ecx                                 ; Move AX to (unsigned int)ECX
movzwl -0xc(%ebp),%eax                          ; Load 'r'->EAX
lea    (%ecx,%eax,1),%eax                       ; 'WriteOffset' + 'r'->EAX
cmp    %eax,%edx                                ; (unsigned int)'WriteOffset+r' == (unsigned int)'buff[r]'
je     0x445e28 <Test+1254>                     ; If == skip {} block

My question is why is the compiler dropping my &0xFF from the if (I have already fixed the problem with a cast, but I still do not understand why it dropped it in the first place)?

  • 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-30T05:10:38+00:00Added an answer on May 30, 2026 at 5:10 am

    It isn’t, operator precedence is biting you here

    You want if( buff[r] != ((WriteOffset+r)&0xFF) )

    What you currently have is the same as if( (buff[r]!=(WriteOffset+r)) & 0xFF )

    The precedence confusion is causing you to mask a value that can only be 0 or 1 (the result of the comparison expression) with 0xFF, so the optimizer is quite reasonably removing it.

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

Sidebar

Related Questions

This is pretty much the same problem i have, except with very different code:
i have strange problem doing reporting: i have numerous clients with different issued invoices.
Problem: I have two spreadsheets that each serve different purposes but contain one particular
I have seen this problem arise in many different circumstances and would like to
I have a strange problem working with HTML,CSS in different browsers: Firefox 3.6 and
I have a small problem with Smarty... I have two different template files in
problem is that I have to checkout a different branch for every project. and
The problem I have is reading in multiple lines of integers from a file
i have a quite strange problem. my class has -among others- following memers: GLboolean
I have a few problems with my mod_rewrite rules. There a three different url

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.