Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Ok, so, this is a bit of a weird issue to me. I have this portion of code in my program that uses an if statement to check and see if a page was found in memory, both of which are structs. However, I have an idea of what the output should be and my output is way off so I started checking through some areas to see where it could be coming from and in the process of doing that I ran into this issue. Here in this spot:
if(memory.memory[i].uid==position)
{
i=pages;
found=1; //The page was found in main memory
cout << memory.memory[i].uid << " " << position << endl;
}
The cout there is for testing purposes and is how I found this issue. The memory.memory[i].uid is always equal to 0, but the code inside the if statement runs anyway (so I get huge blocks of "0 ##" with ## increasing as it should be due to the position variable).
Is there any possible reason that would happen? It just doesn't make sense to me that the code inside the statement is being executed despite the statement being false. Both of the variables in the statement are integers.
(I'm not sure how much more of the code would be needed, it's a big program spanning 3 files so I didn't want to include all of it if I can avoid it. If more is needed though I can edit more in.)
EDIT: Wow, I'm blind. I just realized I'm modifying i before that statement so it's not the same i being used in the statement. After fixing it so the statement was before the modification of i the values are matching as they should be, sorry for the waste of time.
Re-assigning to i between the comparison and the printing can of course give the expression memory.memory[i].uid a different value. If you want to see the value that's used in the comparison, make sure you capture it before re-assigning to i.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 days ago.
Improve this question
I am currently writing my code to develop a grid over an airfoil in 2-D. Within one of my nested DO loops, i keep getting the "unclassified statement at (1)", no matter the bounds for the ELSE statement. Please see below for a copy of the nested loop.
!This will determine x-spacing over top of the airfoil`
DO j=1,nodes
DO i=rem+1,nodes-rem
IF (i<(nodes-rem)-((JLair-1)/2)) THEN
x(i,j)=c*(EXP(Kappaairfoil*((i-(rem+1))/(JLair-1.0)))-1.0)/(EXP(Kappaairfoil)-1.0)
ELSE IF (i==(nodes-1)/2+1) THEN
x(i,j)=c/2.0
ELSE
x(i,j)=c*(EXP(Kappaairfoil*((nodes-(rem+1)-i))/(kJLair-1.0)))-1.0)/(EXP(Kappaairfoil)-1.0)
END IF
END DO
END DO
However, when I run the code, I receive the following error:
gridspacing_2.f95:84:7:
84 | x(i,j)=c*(EXP(Kappaairfoil*((nodes-(rem+1)-i))/(kJLair-1.0)))-1.0)/(EXP(Kappaairfoil)-1.0)
| 1
Error: Unclassifiable statement at (1)
I have been able to get the code to not throw the error if I simply set x(i,j) equal to c, or very simple functions, but when I try to apply the full Rakich stretching function, I immediately receive the unclassified statement error. I appreciate you taking the time to read my problem, Any help is greatly appreciated.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 11 months ago.
This post was edited and submitted for review 11 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I’m trying to make a tic-tac-toe program; I'm adding an if statement to change a variable's value if the condition is met. But when the condition is met, the variable that's value should be changed is 0.
I'm doing this in c++
cout <<player1 << ", which position would you like to add your X?: " << endl;
cin >> x1;
if (x1 == (b)) {
xx1=5;
}
N.B. When it asks you which position would you like it add your X, I am typing "a".
I expected xx1's value to change to 5 but instead of 5 it was 0.
Edit: I was using the "=" operator instead of the "==" operator. I ran the code and it worked, though now, a couple minutes later, it isn't working. I don't know what I did to make this happen, because the only thing that I did was setting it up for other letters.
To check if variables are equal you should use == operator.
You can read more about comparison operators here
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
So what I'm trying to do is simple; I want to write a function into the memory of another process and execute it. What I've done is gotten the size of the function and just used WriteProcessMemory to do this. I have successfully created a thread to run this function, confirmed using cheat engine's debugging features.
The function looks like so:
inline void __cdecl Test( )
{ }
Looks pretty simple. It shouldn't rely on anything that needs to be relocated, so it should work just fine. It is inline because I defined it in a header, if that is relevant. Although this function does NOTHING, this is what is happening in cheat engine:
It's odd that it's copying a string, but more so that it's calling a function? Since this random function call is happening, the program crashes because the address isn't relocated to match where functions are in the new process. So, my question is: why in the world is it calling a function and how can I stop this from happening?
So basically, debug mode was the cause for this issue and does not occur in release.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
When I execute my program it doesn't terminate. I haven't changed anything and it has been working before. There is clearly something wrong but I don't understand what and why.
In the screenshot you can see the line
for ( size_t n = 0; n <= (size_t)maxState; n++ ) nodes.push_back(nullptr);
You can also see that maxState is -1, so (size_t)maxState should be 0. On the right side of the image you can see the values for n and the size of the nodes vector.
I've taken the screenshot after pausing execution. When I resume it doesn't terminate. I've read some things about heap corruption, but without working solutions. Also I'm not sure if heap corruption is the real cause for this strange effect.
I already tried to clean and rebuild.
Don't mess with size_t here. You haven't mentioned the actual type of maxState, but if its value is -1, then it's a signed type. So use a signed index variable:
for (int i = 0; i < maxState; ++i)
This will execute zero times when the value of maxState is negative.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
edit: Sorry about that, I put in the wrong vector. And this is the non working code. The line 'stage_4.resize(20, vector(20, 0));' is giving me the error. 'stage_4.resize(20); works, but I couldn't get it to compile by adjusting both dimensions. Also, I forgot to mention I'm using Code::Blocks 13.12 and Mingw32-gcc.
I'm relatively new to c++ and have basically learned by reading tutorials on the internet so there are some pretty big gaps in my understanding of it. I've been trying to write a program using more classes to make things more streamlined and just started looking into using vectors. However, I've hit a bit of a snag in the combination of the two. I've created a class, and made a vector within it. It all compiles fine until I try to resize the vector as a 2 dimensional array within a function of the class. Here's the relevant code.
class stage{
public:
std::vector<int> stage_4;
int setup(int a){
switch (a){
case 1:
stage_4.resize(20, vector<int>(20, 0));
break;
}
}
}
When I just do stage_4.resize(20); It compiles no problem. But when I try to change both dimensions of the array, like in this code, it tells me "error: 'vector' was not declared in this scope". I'm not really sure what I'm doing wrong since, as I said, I'm fairly new to c++.
edit: I also tried to do stage_4.resize(20, std::vector(20,0));, but then it tells me "no matching function for call to 'std::vector::resize(int, std::vector)'"
It's std::vector.
vector lives in the std namespace.