I am writing a program on Visual Studio 2010, and declaring a variable as follows :
int image[512][512];
and the program run well. But when I modify the program as follows:
int image1[512][512];
int image2[512][512];
it is ok when compiling, but error when execution. The program stopped. Any suggestion?
Are you declaring these as non-static local variables? If so, you may be overflowing the (not too big) stack.
Related
Is there a way within an Intel Visual Fortran project to get a string representing the Visual Studio Solution Directory?
Get_Environment_Variable doesn't seem to have that ability as far as I can tell.
Intel Fortran 2017 and VS 2015.
From your other comments, it seems to me that you're possibly more interested in the directory containing the executable. If you know your solution directory structure you can work out the solution location from that.
You do this in two steps. First you call the Windows API routine GetModuleHandle, passing NULL as the argument. This returns a handle to the current executable. Then you pass this handle to GetModuleFileName which returns the path to the executable as a NUL-terminated string.
If you wanted to separate out just the path, you could use the Intel library routine SPLITPATHQQ.
Example:
program whereami
use kernel32
use, intrinsic :: ISO_C_BINDING
implicit none
integer(HANDLE) :: h
character(MAX_PATH) :: f
integer(DWORD) :: ret
h = GetModuleHandle (NULL)
ret = GetModuleFileName (h,f,len(f))
print *, f(1:index(f,C_NULL_CHAR)-1)
end program whereami
Within the property pages for an Intel Fortran project you can use the $(SolutionDir) macro to query the solution directory.
There are a number of ways to then incorporate the value of this macro into Fortran source when it is compiled (e.g. define a preprocessor symbol on the compiler command line and then reference that preprocessor symbol in the source), or pass the value of that macro to a runtime instance of your program (e.g. through a command line argument, specified via the relevant project property) when the program is started from within Visual Studio.
I am getting an error "the system cannot find the file specified" in Visual Studio C++ when I try to run my program.
You pressed F5 to start the program.
The code was compiled.
The linker failed because it couldn't find int main()
This means there was no program to run.
To fix it you need to define a function called main* that will look like this:
int main (void)
{
// Call the function that you think starts your program, i.e.
Bob();
wprintf(L"Press enter to exit\n");
return fgetc(stdin);
}
The press F7 to make sure it compiles.
Once it has compiled you can use F5 again.
*All C, C++ programs have to have a function called main its the first user visible function that is called. All your code will be called from within main.
Some times main is 'hidden', such as wmain of MFC GUIs, etc.
I can only guess, because you have not given enough information.
Nevertheless, at first I would check the compiling options of the solution and projects for any wrong or missing paths.
If that would not fix the issue, I would check if I have access to all the directories.
Besides, I would avoid using space in any names or paths, because those can cause issues too. I would use camel case notation instead.
Can a good IDE (e.g. Visual Studio) find basic logic errors?
or is there no such thing as a "basic" logic error and all of these errors are undetectable by the IDE?
Yes, some IDEs (like Visual Studio) have continous syntax checks, that can find some logical errors. However, a logical error can only be spotted if there is something odd in the code, there is no AI trying to figure out what the code is actually intended to do.
If you for example write this in a C# method in Visual Studio:
int a = 1;
int b = 2;
Console.WriteLine(a + a);
then the IDE will notice that you never used the variable b, and put a warning in the form of a squiggly line under the variable. Pointing on it will reveal the message The variable 'b' is assigned, but its value is never used.
The IDE can't know if you intended to output a + b rather than a + a, and simply the use of a + a is not odd enough to render a warning, but it can see that you created a variable b and that you probably intended to use that for something.
Not really.
Sometimes it can pick up that a code path may never execute I think.
int x = 9;
if (x != 9)
{
foo();
}
and it maybe able to tell you that you've declared something without using it. It's stuff you can catch yourself. However, the real power is in the debugger where you can use "watch" or locals/autos and follow the code with step-in/out/over at any scope, see when they change, and change the values yourself to see what needs to happen. It's a good way to test logic. In assembly, you can move your code back a few lines and repeat it... it's not guaranteed to work, but you can override anything.
Edit: see https://en.wikipedia.org/wiki/Halting_problem
I tried some suggestions found online but it does not work for me. Im using Visual Studio 2010. Basically I typed loc(kcs(1,4)) (thats my variable) and I obtained 157510036. Its hex is 9636994. So then I typed (INTEGER*)0x9636994 but on the watch window under the "value"column it says "undefined variable INTEGER". I trid lowercase integer or real and same answer. Any suggestion?
I typed (INTEGER*)0x9636994 but on the watch window under the "value"column it says "undefined variable INTEGER".
According to Restrictions on Native C++ Expressions:
Type Casting
If you cast to a type, the type must be known to the debugger. You must have another object of that type in your program. Types created using typedef statements are not supported.
Try using the underlying type. So, for example, if INTEGER is actually an int you would try to watch (int *)0x9636994.
This also assumes that the variable is fixed at 0x9636994 (basically that you're not trying to refer to something transient on the stack).
I did a research on web and cannot find anything so maybe you know a way to solve my problem.
I am using MS VS 2010, and I use VS C++ (only CLR).. Let's say I have a class smt like this:
class A
{
public:
int x;
float a;
char* str;
};
While debugging my application, I open "Locals Window" and I see my variable name, value and Type. I would like to change (write) something to my value part. Like I habe a class A object a:
Name Value Type
a x: 4 a: 2.03f str: 'Hello!' A
I hope this was a clear example. I want to override value part in locals, autos ... windows.. Any way to do it?
Thanks...
If the class is a managed class then you can decorate it with a DebuggerDisplayAttribute. If it is unmanaged, which your example seems to be, then you need to edit a file called autoexp.dat. There's a fairly old article on MSDN about it here, I have done this a long time ago and remember it was a pain to get working. Also, there is a bug filed on Connect that autoexp.dat doesn't work for C++/CLI projects in VS 2010, though I haven't tried this myself.