Are there strategies or methods to identify whether a particular piece of code or program will generate a link error or a compile error.
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:
- Ideon
- Codepad's online compiler/parser
Comeau's "try it out" web-based compiler
(thanks commenters for the updates)
This will just help you with compiling what's in the web form though, linking and producing an executable is another story...
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)
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.
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.