trouble executing C code in Visual Studio.Net environment

This is a discussion on trouble executing C code in Visual Studio.Net environment within the C Programming forums, part of the General Programming Boards category; Hi, I'm trying to execute a C program in Visual Studio.Net 2003 environment and seem to have a problem with ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    4

    trouble executing C code in Visual Studio.Net environment

    Hi,
    I'm trying to execute a C program in Visual Studio.Net 2003 environment and seem to have a problem with the watch window in the IDE. I wrote a simple code like:

    Code:
    #include<stdio.h>
    main()
    {
    	int arr[2][2]={
    		{2,3},
    		{3,5},
    	};
    	printf("&#37;d",arr[0][1]);
    }
    when attempting to execute this code in debug mode, if i try to view the contents of arr[0][1] in the watch window, I get the following error message
    arr[0][1] error: index '0' out of bound for pointer/array 'arr'

    The printf statement prints the correct value of 3 for arr[0][1]. I was wondering what I'm missing in the watch window.

    Appreciate your help.
    Last edited by ridhamshah; 02-18-2008 at 02:09 AM.

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    I'm not sure why it's doing that. I compiled with VC++ 2005 express and the watch window shows the value just fine.
    BTW, this is how your code should look:
    Code:
    #include<stdio.h>
    int main()
    {
    	int arr[2][2]={
    		{2,3},
    		{3,5}   /* ,  You don't need a comma here. */
    	};
    	printf("%d",arr[0][1]);
    	return 0;
    }

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    4
    For some weird reason, my 2D array "arr" in the watch window appears to be initialized as a 3D array as below:

    Code:
    arr	{Length=2}	__int32[][][]
    I can't quite understand what is wrong here. This is the simplest code for a 2D array one can ever write. Visualstudio.net is making it hell.. Apparently, this is a Microsoft Visual Studio.Net 2003 bug:. http://support.microsoft.com/kb/326721

    Now, I guess my problem is that I don't quite understand their resolution. How do you use managed type (instead of unmanaged type) in a multidimensional array ?
    Last edited by ridhamshah; 02-18-2008 at 09:24 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  2. Templates and Macros plus more...
    By Monkeymagic in forum C++ Programming
    Replies: 8
    Last Post: 01-20-2007, 04:53 PM
  3. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  5. Replies: 1
    Last Post: 05-26-2004, 09:59 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21