Are there strategies or methods to identify whether a particular piece of code or program will generate a link error or a compile error.

+5  A: 

You mention in your comments "if you don't have access to a compiler". Well if you have access to the web you have access to a compiler:

This will just help you with compiling what's in the web form though, linking and producing an executable is another story...

Doug T.
Oh god that page is ugly... use this one instead: http://codepad.org/
@Mark: What Comeau lacks in website beauty it makes up for with standards-conforming awesomeness.
James McNellis
Oh it's not comeau to prise. It's EDG to prise here. Comeau just know how to advertise :) You may also wanna try http://ideone.com/ . It supports stdin, processes, doesn't cut error messages and has a more recent GCC version.
Johannes Schaub - litb
+3  A: 

The best way is to compile and link your program.

You can download a compiler pretty easily. For windows the smallest and best for me that I've found is MinGW. With it you can compile all your code via the command prompt.

If you have a Mac or Linux then you have a compiler already there installed with the OS. Either way you can write programs with any text program then compile the source from the command line. Here are a couple suggestions for text programs that are good for coding with:

Notepad++ (Windows only)


Mike Webb
+1  A: 

Perform a dry run


You can use some sort of syntax checker like the one Eclipse (C/C++ development) has, this will check for most syntax errors (I think it does also type checking). There are also flymake/emacs that does a great job in the same way.

For linking errors I don't think it's possible a-priori.


Without an IDE, you can use makefiles to do the job. With proper rules in makefiles, you can compile modules separately and then link them all. There by you will get errors specific to modules and then at the end errors due to linking. There are tools that can generate makefiles for various platforms and compilers like - automake, CMake, Apache Ant to name a few.

+2  A: 

It is never a good idea to try to work out in advance whether a piece of code will produce a compilation error. Back when I was an instructor teaching C++ for a commercial training company, I would sometimes see a trainee gazing intently at the monitor but not typing anything:

Me: What's the problem?

Him: Oh, I'm just checking through the code before I compile it.

Me: Gaah! (well, I thought that)

Don't be like him. Run the compiler over the code at every possible opportunity you get. And we live in a world where high quality compilers are so easily available that it is ridiculous to do anything else.


Without using a compiler, code and design reviews are a good start.

There are tools such as lint, PCLint that parse through the source code looking for potential threats such as uninitialized variables and memory leaks. An extreme application in this genre is Klocwork.

Thomas Matthews