A.
You can scroll the window by dragging the scrollbar with the middle
mouse button (on UNIX machines) or pipe the output to
"less"
, by typing the following at the UNIX prompt:
compile-command |& less
(Make sure to replace compile-command with the UNIX command you use to compile.)
The "|"
pipes standard output into the program
less
and the "&"
makes sure standard
error goes there too.
A.
Sounds like you are trying to compile a .h file? Only .c files need to
be compiled, since .h files are #include
'd.
"somefile.c", line 85: warning(1116): non-void function "SomeFunction" (declared at line 51) should return a value } ^
A.
Here's likely the problem...
if (some-condition) return some-value; }
It is possible (though not if only valid data is used) for someone to
get past all the ifs
in the function. Note that after
this last if
(listed above), there is no code to return
anything. Now, since the function returns "int
" and the
compiler has identified a case in which it is possible that nothing
gets returned, it complains.
Fix it so that the function always returns something, and likely the error will go away.
gcc prog.c
I get:
What's the problem?/var/tmp/cc2sdOi_1.o: In function `main': /var/tmp/cc2sdOi_1.o(.text+0x4): undefined reference to `Foo'
A.
First, make sure you spelled the function "Foo" the same when you
prototype, define and call it (remember, upper/lowercase must match
too). If that's ok...
Make sure you included all the .c files that make up the program in the compilation command, as in:
gcc prog.c module1.c module2.c ...
If this function (Foo()
) is defined in a module
(i.e., not in prog.c
), that module must be compiled with
the rest of the program. This is necessary even if you correctly
include the header files for the module (i.e., if you have a prototype
for that functon). Prototypes don't produce any code, they only tell
the compiler what type of things a function takes and returns. The
function definitions define the code for a function.
In any case, it is probably better to write a Makefile for programs with many source code files.
A.
Are you #include
'ing the ".c" file? Only include ".h" files.
A.
Often, this has to do with a missing prototype. When the compiler has
no prototype for a function, it assumes that the function returns an
int
. Missing a prototype, of course, is bad since the
compiler cannot check the parameters (to make sure they are the right
type or to convert them to the right type) and cannot check the return
type. Adding the prototype or including the correct header (which has
the prototype) is the solution.
A.
It probably means some header file is included twice (either directly
or indirectly). It's ok for headers to be included multiple times
(more often indirectly), but you must wrap these headers?
A.
It probably means you are trying to do something like:
var.fieldName
where var is not a structure, and thus, has no field fieldName.
A.
It probably means you are trying to dereference a pointer to a
struct
(i.e., use star (*
) or arrow
(->
) with it) in code where that struct
is
not defined. Are you trying to dereference an ADT outside of the
.c
file where its CDT is defined?
A.
You are missing the #endif
that goes at the end of the
header.
gdb
, it says "program exited with
code 01"?
A.
Function main()
should return 0 to signify the program
went fine...If you don't explicitly return 0 from main()
,
then the return value from the program will be some arbitrary value.
Note that these comments are also relevant to what you provide as an
argument to function exit()
.
0xef746954 in memcpy ()
and when I type the Gdb where command it says it cannot access memory at address 0xef7fffb0. What does this means?
A.
It means that the Seg fault doesn't occur directly in one of
your functions, but in a library function named memcpy()
.
Of course, it still means you've done something bad in your code.
First, make sure you compiled your program with the -g option (to get debugging information). Then, if you still cannot get context information (i.e., what piece of your code led to the error) from the where command in Gdb, you'll have to do more work....I.e., either by using printfs, like:
printf("Point A\n");
(don't forget the newline) or by setting breakpoints (in Gdb), narrow down the region where the error occurred until you find the single line where the problem is.
Remember that Segmentation Faults often occur when using a pointer improperly or with arrays (e.g., using an index that is out-of-range).
A.
You could use a single global int
counter variable. Start
the variable out at 0. Then wherever you have a malloc
,
add code to increment the counter. Wherever you have a
free
, add code to decrement the counter.
Then, print the counter whenever you want to see what it is OR monitor the counter from inside the debugger.
The only thorough method is to keep track of the addresses of
things when they are allocated, and make sure all those same addresses
are parameters to calls to free
at some point.
A.
Are you forgetting to put Tab characters at the beginning of
the lines with compilation/linking commands?