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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:47:06+00:00 2026-06-05T10:47:06+00:00

Why do uninitialized max and min values work on Linux but not Windows? For

  • 0

Why do uninitialized “max” and “min” values work on Linux but not Windows? For example:

double max, min, test;
while (1)
{
  std::cin >> test;
  if (test > max)
    max = test;

  if (test < min)
    min = test;
}

This works on Linux. I know for a fact because I’ve been using this (although I didn’t realize until now how terrible this is) for at least 3 months now. However, I’ve been told by a number of co-workers that this is broken on their machines: They compile using Visual Studio. Is there some validity to their statements, and why? Is this simply a case of UB? If so, how has it been working for the past months without me noticing?

Also note: gcc (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2 and Visual Studio 2010

  • 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-05T10:47:08+00:00Added an answer on June 5, 2026 at 10:47 am

    Roughly speaking, your code will appear to work if the uninitialized variables min and max just so happen to hold values that compare in between the actual minimum and maximum values encountered in test. The object representation of an uninitialized automatic variable may or may not be consistent, depending on compiler, options, and the code in the rest of the program. Reading an uninitialized value is certainly UB. UB may or may not be consistent.

    So for example, one simple way that you could get the behavior you observe is if:

    • your test sets all include both positive and negative values,
    • gcc/linux consistently puts an all-bits-zero representation in the uninitialized variables,
    • VS consistently puts a NaN in the uninitialized variables (so test < min and test > max are both always false).

    Depending on what your test data is, and what “broken on their machines” means, the details may be different. I’ve just described one possibility out of the infinite scope of UB.

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

Sidebar

Related Questions

Is there a way to construct a new std::vector with uninitialized (non-zero) values or
We were having a debate if enums should have uninitialized values. For example. We
i used ree to test dalli gem, but i got one error: uninitialized constant
So I've been getting some mysterious uninitialized values message from valgrind and it's been
Possible Duplicate: Why do I see strange values when I print uninitialized variables? Fun
I'm getting uninitialized constant Date (NameError) with the following code: class Test attr_accessor :reqs
I tried using logger.info Rails Environment #{RAILS.env} but I'm getting an error: uninitialized constant
I'm having this strange error for the devise_invitable extension: uninitialized constant ActiveSupport::SecureRandom But the
I understand from the answer to this question that values of global/static uninitialized int
I have a static variable declared but uninitialized in a function. Will this variable

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.