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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:34:11+00:00 2026-05-13T12:34:11+00:00

The following code gives different output when running the release inside Visual Studio, and

  • 0

The following code gives different output when running the release inside Visual Studio, and running the release outside Visual Studio. I’m using Visual Studio 2008 and targeting .NET 3.5. I’ve also tried .NET 3.5 SP1.

When running outside Visual Studio, the JIT should kick in. Either (a) there’s something subtle going on with C# that I’m missing or (b) the JIT is actually in error. I’m doubtful that the JIT can go wrong, but I’m running out of other possiblities…

Output when running inside Visual Studio:

    0 0,
    0 1,
    1 0,
    1 1,

Output when running release outside of Visual Studio:

    0 2,
    0 2,
    1 2,
    1 2,

What is the reason?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test
{
    struct IntVec
    {
        public int x;
        public int y;
    }

    interface IDoSomething
    {
        void Do(IntVec o);
    }

    class DoSomething : IDoSomething
    {
        public void Do(IntVec o)
        {
            Console.WriteLine(o.x.ToString() + " " + o.y.ToString()+",");
        }
    }

    class Program
    {
        static void Test(IDoSomething oDoesSomething)
        {
            IntVec oVec = new IntVec();
            for (oVec.x = 0; oVec.x < 2; oVec.x++)
            {
                for (oVec.y = 0; oVec.y < 2; oVec.y++)
                {
                    oDoesSomething.Do(oVec);
                }
            }
        }

        static void Main(string[] args)
        {
            Test(new DoSomething());
            Console.ReadLine();
        }
    }
}
  • 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-13T12:34:12+00:00Added an answer on May 13, 2026 at 12:34 pm

    It is a JIT optimizer bug. It is unrolling the inner loop but not updating the oVec.y value properly:

          for (oVec.x = 0; oVec.x < 2; oVec.x++) {
    0000000a  xor         esi,esi                         ; oVec.x = 0
            for (oVec.y = 0; oVec.y < 2; oVec.y++) {
    0000000c  mov         edi,2                           ; oVec.y = 2, WRONG!
              oDoesSomething.Do(oVec);
    00000011  push        edi  
    00000012  push        esi  
    00000013  mov         ecx,ebx 
    00000015  call        dword ptr ds:[00170210h]        ; first unrolled call
    0000001b  push        edi                             ; WRONG! does not increment oVec.y
    0000001c  push        esi  
    0000001d  mov         ecx,ebx 
    0000001f  call        dword ptr ds:[00170210h]        ; second unrolled call
          for (oVec.x = 0; oVec.x < 2; oVec.x++) {
    00000025  inc         esi  
    00000026  cmp         esi,2 
    00000029  jl          0000000C 
    

    The bug disappears when you let oVec.y increment to 4, that’s too many calls to unroll.

    One workaround is this:

      for (int x = 0; x < 2; x++) {
        for (int y = 0; y < 2; y++) {
          oDoesSomething.Do(new IntVec(x, y));
        }
      }
    

    UPDATE: re-checked in August 2012, this bug was fixed in the version 4.0.30319 jitter. But is still present in the v2.0.50727 jitter. It seems unlikely they’ll fix this in the old version after this long.

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

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You probably want to call setlocale() first, "LC_ALL" should do… May 14, 2026 at 9:06 am
  • Editorial Team
    Editorial Team added an answer Linux Ubuntu Desktop Jaunty Firebug FireCookie Pixel Perfect Web developer… May 14, 2026 at 9:06 am
  • Editorial Team
    Editorial Team added an answer Your code should look like this: var par = [];… May 14, 2026 at 9:06 am

Related Questions

I have had a hard disk failure which resulted in some files of a
I have already read Using Java to encrypt integers and Encrypting with DES Using
So we've produced a windows service to feed data to our client application and
I am new to Haskell and trying to fiddle with some test cases I
EDIT: See my working code in the answers below. In brief: I have a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.