![]() |
| | #1 |
| Registered User Join Date: Jul 2009
Posts: 1
| |
| richi is offline | |
| | #2 | |
| Webhead Join Date: Jul 2009
Posts: 278
| Quote:
| |
| Spidey is offline | |
| | #3 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,787
| Usually because you made a run-time error and not a compile-time error. For more information, we need to see code!
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #4 | |
| critical genius Join Date: Jul 2008 Location: SE Queens
Posts: 5,234
| Quote:
Code: #include <stdio.h>
#include <string.h>
int main() {
char *overflowme;
strcpy(overflowme,"this will overwrite some memory");
printf("%s", overflowme);
return 0;
}
On the other hand, programming need not be quite so easy as throwing darts blindfolded (which really is easy if you don't care what you hit). You have to know what you are doing. To know you have to learn, partially thru a process of trial and error. It's not nearly as painful as learning to ride a bike, and you already did that (hopefully). Lesson: Don't expect the compiler to fix everything for you, and be happy when it does. | |
| MK27 is online now | |
| | #5 |
| Making mistakes Join Date: Dec 2008
Posts: 347
| A compiler doesn't check if you're doing meaningful things. It only checks if you're doing correct things. I don't think many compilers will complain at this: Code: #include <stdio.h>
int main(void)
{
printf("The mystery is solved: *NULL is %d\n", *(int *)NULL);
return 0;
}
|
| Brafil is offline | |
| | #6 |
| Registered User Join Date: Sep 2008 Location: Toronto, Canada
Posts: 525
| Compilers can't check logic errors or care much whether there are even any output statements. That should be obvious. |
| nonoob is offline | |
| | #7 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,787
| They can, and some do.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #8 |
| Malum in se Join Date: Apr 2007
Posts: 3,188
| The compiler just checks to make sure you use correct syntax, it doesn't check to make sure your code is coherent. The warbling of the instantiated was blue. Perfectly good syntax, with no meaning whatsoever.
__________________ Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off. |
| abachler is offline | |
| | #9 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,787
| No, some do. 99% of the compilers do not, but some, like MSVC can check for problems like this. It's not good to dismiss out of hand. But it's certainly not good to always rely on such a feature.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #10 |
| critical genius Join Date: Jul 2008 Location: SE Queens
Posts: 5,234
| And if you do this: Code: int mostlypointless (int x) {
int a = 12, i;
for (i=0; i<10; i++) a = a*i+a;
return x+1;
}
The only way to notice this (I guess) is if you use massive meaningless loops for profiling. Compiled gcc -O3, they won't happen. Last edited by MK27; 07-25-2009 at 04:34 AM. |
| MK27 is online now | |
| | #11 |
| Super Moderator Join Date: Aug 2001
Posts: 7,819
| Newer compilers for other languages are 'attempting' to do this and it comes off to me as 100% annoying. Maybe it's because I don't like my hand being held while I code.
__________________ If you aim at everything you will hit something but you won't know what it is. |
| Bubba is offline | |
| | #12 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,787
| It's extremely helpful to offer such code analysis, because it can find problems in your code. Naturally, it is also slower, so there should always be an option to turn it off. Otherwise the compiler is flawed. Or perhaps you don't like the compiler removing certain code in optimizations?
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #13 |
| Unregistered User Join Date: Jul 2007
Posts: 982
| >> They can, and some do. To a very limited extent, but for the most part they can't. When it comes to incorrect manipulation of certain things, 'const' does a good job for protecting against this - if for some reason the programmer doesn't want to use it, that's his problem.
__________________ May the Source be with you. |
| Yarin is offline | |
| | #14 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,787
| Const doesn't help very much at all. It's mostly for for convenience and efficiency.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #15 | |
| (?<!re)tired Join Date: May 2006 Location: Portugal
Posts: 5,663
| Quote:
That type of code analysis can and should be done by specialized tools only. MSVC offers those tools in its Team System releases. Tools like Code Metrics, C/C++ Code Analysis Tools, Application Verifier, Line Level Sampling and even Code Profiler (and there's even more). Note that by "compiler", I mean the actual task of code compilation. In this context I don't agree such tasks should be implemented. In fact I suspect most of them couldn't, since better diagnostics can only be achieved after compilation and during program execution with access to debugging symbols, which is what most of the tools above do. On the other hand, if we consider the tasks of a compiler (lexical analysis, pre-processing, parsing and code generation with/without optimization) we can see there is really no place for such analysis as the excellent example provided by Mk27 demonstrates. Again, go back to abachler statement. There's an underlying truth to it that basically says it's not the task of the compiler to make sure your code works as you want it to.
__________________ Originally Posted by brewbuck: Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster. Last edited by Mario F.; 07-25-2009 at 01:16 PM. | |
| Mario F. is online now | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Recommend upgrade path for C programs | emanresu | C Programming | 3 | 11-22-2007 07:32 AM |
| Way to get the current open programs displayed? | CPPguy1111 | C++ Programming | 6 | 06-22-2005 12:24 AM |
| Communication between programs? | johny145 | Windows Programming | 3 | 06-01-2005 10:14 PM |
| POSIX/DOS programs? | nickname_changed | C++ Programming | 1 | 02-28-2003 05:42 AM |
| executing c++ programs on the web | gulti01 | C++ Programming | 4 | 08-12-2002 03:12 AM |