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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:09:48+00:00 2026-06-02T02:09:48+00:00

This code, when compiled with Visual Studio 2010 #include <cstdlib> #include <cstdio> int numbers[]

  • 0

This code, when compiled with Visual Studio 2010

#include <cstdlib>
#include <cstdio>

int numbers[] = { 23, 24, 25, 25, 28, 20, 20 };

int main(void) {
    int d = -1, x=0;
    size_t count = sizeof(numbers) / sizeof(numbers[0]);

    if (d <= (sizeof(numbers) / sizeof(numbers[0]))-2)
        x = numbers[d+1];

    if (d <= count-2)
        x = numbers[d+1];
}

gives me a signed/unsigned mismatch warning on if (d <= count-2) but not on if (d <= (sizeof(numbers) / sizeof(numbers[0]))-2). Why is this? I have enabled all warnings.

  • 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-02T02:09:49+00:00Added an answer on June 2, 2026 at 2:09 am

    It is a bug that the Visual C++ compiler does not emit warning C4018 in this case. See the Microsoft Connect bug report, “warning C4018 (signed/unsigned mismatch) for sizeof operator.”

    The issue appears to be only indirectly related to usage of sizeof. The compiler also fails to emit the warning in other cases where a constant value of unsigned type is involved in the comparison. For example, if you add const-qualification to count, C4018 is not emitted even for your second comparison.

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

Sidebar

Related Questions

I wrote this simple C code and compiled it using Visual Studio 2010, with
I don't understand why this code #include <iostream> using namespace std; int main(){ int
I have a code snippet like this, to be compiled under VC++ 2010. std::set<int>
In my application (compiled under Visual C++ 2010), I have code like this in
This code compiles fine with GCC and Clang but not with MSVC 2010: #include
Using Visual Studio 2010 SP1: #include <vector> //namespace XXX { struct Test { bool
Could anyone please explain why this code compiles : #include <stdio.h> #include <string.h> int
This code, when compiled in xlC 8.0 (on AIX 5.3), produces the wrong result.
i am using this code to check if my glsl shader compiled fine. glGetObjectParameterivARB(obj,
How can this code compile? The code below in the operator int CAN access

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.