I tried to run the makefile on https://github.com/nasadi/Zambezi. It shows an error like:-- "file included from src/driver/buildContiguous.c:7:0: src/shared/dictionary/Dictionary.h: In function ‘readDictionary’: src/shared/dictionary/Dictionary.h:132:8: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result] fread(&id, sizeof(int), 1, fp);" . Can anyone help me to run the program.Do i need to install any packages.I am new to c programming.
In fact, this is not an error, it is a warning. When compiler emits a warning, it means that code is syntactically correct but may potentially contain logic error.
In your case compiler says that return value of the fread function is not examined. Such ignorance can lead to a situation, where, for e.g., end of file is encountered, but the program is unaware of it and continues execution. Therefore, variable read from file have wrong value, and wrong (invalid) values may cause program crash later on.
Summarizing, if there are no other errors, then your program is successfully compiled and can be run.
Related
The code that I am working with was originally written in FORTRAN 77. I am hesitant to update all of the files to a more modern standard since there are multiple files thousands of lines long that rely on obsolete functions.
During compilation, I get a few type mismatch arguments, most of which are taken care of with -freal-4-real-8, but I am unsure if that is a permanent solution.
I currently use the following flags to compile all of the object files which are then compiled into the final executable: -ff2c -std=legacy -freal-4-real-8
The file in which the error occurs is compiled without the -freal flag because it uses a function that requires a real(4) variable.
The current error I am getting upon running the executable is:
At line 2680 of file twopt.f
Fortran runtime error: Assigned label is not a target label
The subroutine in which the error occurs takes in REENT as a logical parameter. ROUTE is later declared as an integer but is not assigned any value which I think might be the reason behind the problem. I used print statements to check its value before the error occurs, and REENT is true, and ROUTE is 0.
Code at lines 2678-2681:
IF (REENT) THEN
REENT = .FALSE.
GO TO ROUTE
END IF
In the subroutine there is no statement label with the value of 0 which also might contribute to the error. Again, I am hesitant to edit the code too much since it supposedly worked as intended back in the ‘90s. Any help would be greatly appreciated.
I'm trying to use the gfortran option -fcheck=bounds,pointer to look for runtime errors in some code. What do the error reports look like, and where/when do they appear? Are they written to standard error, or output, or some file? Are they written and flushed at the point of occurrence, or at the end of execution? Does an error report terminate execution?
In reverse order
An error report does terminate execution
This obviates whether they're buffered or flushed immediately
They're written to standard error
Passing an invalid pointer to a routine looks like this:
At line 556 of file ../../topslave.F
Fortran runtime error: Pointer actual argument 'buffer2' is not associated
I am running an atmospheric model, and need to compile an executable to convert some files. If I compile the code as supplied, it runs but it gets stuck and doesn't ever complete. It doesn't give an error or anything like that.
After doing some testing by adding print statements to see where it was getting stuck, I've found that the executable only runs if I compile the code with a print statement in one of the subroutines.
The piece of code in question is the one here. Specifically, the code fails to run unless I put a print statement somewhere in the get_bottom_top_dim subroutine.
Does anyone know why this might be? It doesn't matter what the print statement is (currently I'm using print*, '!'). but as soon as I remove it or comment it out, the code no longer works.
I'm assuming it must have something to do with my machine or compiler (ifort 12.1.0), but I'm stumped as to what the problem is!
This is an extended comment rather than an answer:
The situation you describe, inserting a print statement which apparently fixes a program, often arises when the underlying problem is due to either
a) an attempt to access an element outside the declared bounds of an array; or
b) a mismatch between dummy and actual arguments to some procedure.
Recompile your program with the compiler options to check interfaces at compile-time and to check array bounds at run-time.
Fortran has evolved a LOT since I last used it but here's how to go about solving your problem.
Think of some hypotheses that could explain the symptoms, e.g. the compiler is optimizing the subroutine down to a no-op when it has no print side effect. Or a compiler bug is translating this code into something empty or an infinite loop or crashing code. (What exactly do you mean by "fails to run"?) Or the Linker is failing to link in some needed code unless the subroutine explicitly calls print.
Or there's a bug in this subroutine and the print statement alters its symptoms e.g. by changing which data gets overwritten by an index-out-of-bounds bug.
Think of ways to test these hypotheses. You might already have observations adequate to rule out of some of them. You could decompile the object code to see if this subroutine is empty. Or step through it in a debugger. Or replace the print statement with a different side effect like logging to a file or to an in-memory text buffer.
Or turn on all optional runtime memory checks and compile time warnings. Or simplify the code until the problem goes away, then binary search on bringing back code until the problem recurs.
Do the most likely or easiest tests first. Rule out some hypotheses, and iterate.
I had a similar bug and I found that the problem was in the dependencies on the makefile.
This was what I had:
I set a variable with a value and the program stops.
I write a print command and it works.
I delete the print statement and continues to work.
I alter the variable value and stops.
The thing is, the variable value is set in a parameters.f90
The print statement is in a file H3.f90 that depends on parameters.f90 but it was not declared on the makefile.
After correcting:
h3.o: h3.f90 variables.f90 parameters.f90
$(FC) -c h3.f90
It all worked properly.
Here's a line of code that I get an error about, which is in my book from 2008: std::cin.get(std::cin.rdbuff()->in_avail()+1);
Could someone please tell me what it means and why it gives me an error:
In function 'int main()':|7|error: 'struct std::istream' has no member named 'rdbuff'|
||=== Build finished: 1 errors, 0 warnings ===|
--update--
changed rdbuff to rdbuf, and it throws this error:
walkthrough.cpp|7|error: no matching function for call to 'std::basic_istream<char, std::char_traits<char> >::get(std::streamsize)'|
The member function is called rdbuf(), one f, as a cursory glance at any library reference will easily reveal.
In other words, the error is that istream has no member named rdbuff.
Kerrek SB already told you the reason for the error: It's rdbuf, not rdbuff.
Now on what this code tries to do: It is trying to enforce a blocking read (that is, it tries to force the program to wait for the user to input something even if there's unread stuff which has been entered before reaching that statement). in_avail gives the number of characters "available", that is, how many characters you are guaranteed to be able to read without blocking, i.e. without the program having to wait for the user to input more.
However that line of code is somewhat misguided because there's no guarantee that reading the next character does block. So it may happen on some system that this line still doesn't wait for user input in some cases.
And even in cases where it does, the input stream will typically be left with a line where the first character was removed, but the rest is available, possibly giving surprising results on further reads if it wasn't an empty line to begin with.
This has been stumping me for a bit. I have a Class written in C++.
Everything works fine.
Next, I add function void A(); to the header file and run, It still works fine.
However as soon as I add a new function definition to the CPP file, I get a runtime error every single time. (specifically: Process terminated with status -1073741510 (0 minutes, 7 seconds)
void ClassName::A() {
}
I am running using Code::Blocks on Windows, also strange but the permissions of the output directory are all changed after the crash and the folders/files are all set to Read Only.
Note: there are NO references/uses of the function elsewhere in the code, only the definition. I am interested in what sort of bug could cause this kind of runtime error? Possibly a memory leak somewhere?
Usually such an error is the result of memory corruption somewhere in the program.
Sounds like you have a wild pointer somewhere.