C Board  

Go Back   C Board > Community Boards > General Discussions

Reply
 
LinkBack Thread Tools Display Modes
Old 07-24-2009, 02:31 AM   #1
Registered User
 
Join Date: Jul 2009
Posts: 1
Unhappy c programs

why some c programs are not run even if there is no error in compile time??????????
richi is offline   Reply With Quote
Old 07-24-2009, 03:14 AM   #2
Webhead
 
Spidey's Avatar
 
Join Date: Jul 2009
Posts: 278
Quote:
why some c programs are not run even if there is no error in compile time??????????
Such as ?
Spidey is offline   Reply With Quote
Old 07-24-2009, 04:04 AM   #3
Mysterious C++ User
 
Elysia's Avatar
 
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:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 07-24-2009, 09:38 AM   #4
critical genius
 
MK27's Avatar
 
Join Date: Jul 2008
Location: SE Queens
Posts: 5,234
Quote:
Originally Posted by richi View Post
why some c programs are not run even if there is no error in compile time??????????
You mean like this one:
Code:
#include <stdio.h>
#include <string.h>

int main() {
	char *overflowme;
	strcpy(overflowme,"this will overwrite some memory");
	printf("%s", overflowme);
	return 0;
}
Because the compiler does not check stuff like this. Perhaps it should, and this is a performance trade-off in the compiler.

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.
__________________

"A man can't just sit around." -- Larry Walters
MK27 is online now   Reply With Quote
Old 07-24-2009, 09:44 AM   #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;
}
Even though it is clearly undefined behaviour.
__________________
Look at this: Community Project
And this: Ascent - Programmer needed
Brafil is offline   Reply With Quote
Old 07-24-2009, 04:06 PM   #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   Reply With Quote
Old 07-25-2009, 03:08 AM   #7
Mysterious C++ User
 
Elysia's Avatar
 
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:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 07-25-2009, 04:11 AM   #8
Malum in se
 
abachler's Avatar
 
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   Reply With Quote
Old 07-25-2009, 04:26 AM   #9
Mysterious C++ User
 
Elysia's Avatar
 
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:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 07-25-2009, 04:29 AM   #10
critical genius
 
MK27's Avatar
 
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;
}
GCC -O3 will just ignore the statements in red as if they didn't exist, because they are meaningless in the context of the program.

The only way to notice this (I guess) is if you use massive meaningless loops for profiling. Compiled gcc -O3, they won't happen.
__________________

"A man can't just sit around." -- Larry Walters

Last edited by MK27; 07-25-2009 at 04:34 AM.
MK27 is online now   Reply With Quote
Old 07-25-2009, 10:29 AM   #11
Super Moderator
 
Bubba's Avatar
 
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   Reply With Quote
Old 07-25-2009, 10:37 AM   #12
Mysterious C++ User
 
Elysia's Avatar
 
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:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 07-25-2009, 12:13 PM   #13
Unregistered User
 
Yarin's Avatar
 
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   Reply With Quote
Old 07-25-2009, 12:29 PM   #14
Mysterious C++ User
 
Elysia's Avatar
 
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:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 07-25-2009, 01:14 PM   #15
(?<!re)tired
 
Mario F.'s Avatar
 
Join Date: May 2006
Location: Portugal
Posts: 5,663
Quote:
Originally Posted by Elysia View Post
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.
Hmm... I disagree. That's definitely not the task of a compiler. Abachler said it best.

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   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 09:36 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22