Unexpected Results

A

arpit

Hi All,
I had a C application. Which sometimes gives correct result and
some time worng or no result under the same env. Can anyone tell me
what are the possible reasons for it like memory or something else.

Although I think it is a kind of Bug , but i wish to know what are
the factors responsible for the bug that some times it is ok and
sometimes it is problem.

looking for suggestions.

Thanks
 
M

Mark Bluemel

arpit said:
Hi All,
I had a C application. Which sometimes gives correct result and
some time worng or no result under the same env. Can anyone tell me
what are the possible reasons for it like memory or something else.

Although I think it is a kind of Bug , but i wish to know what are
the factors responsible for the bug that some times it is ok and
sometimes it is problem.

looking for suggestions.

Hmm... Where did I put my crystal ball?

<looks around>

Nope - can't find it.

<Inspiration strikes!>

I rolled my magic 8 ball and it said :-

"situation unclear - try
<http://www.catb.org/~esr/faqs/smart-questions.html>".
 
S

santosh

arpit said:
Hi All,
I had a C application. Which sometimes gives correct result and
some time worng or no result under the same env. Can anyone tell me
what are the possible reasons for it like memory or something else.

Although I think it is a kind of Bug , but i wish to know what are
the factors responsible for the bug that some times it is ok and
sometimes it is problem.

looking for suggestions.

Yes the problem is on line 42.
 
C

CBFalconer

arpit said:
I had a C application. Which sometimes gives correct result and
some time worng or no result under the same env. Can anyone tell me
what are the possible reasons for it like memory or something else.

Although I think it is a kind of Bug , but i wish to know what are
the factors responsible for the bug that some times it is ok and
sometimes it is problem.

looking for suggestions.

Correct line 42.
 
B

Ben Pfaff

arpit said:
I had a C application. Which sometimes gives correct result and
some time worng or no result under the same env. Can anyone tell me
what are the possible reasons for it like memory or something else.

You will need to tell us more about your application and the
problems that it exhibits. If your program is short, post the
code here.
 
K

Keith Thompson

arpit said:
I had a C application. Which sometimes gives correct result and
some time worng or no result under the same env. Can anyone tell me
what are the possible reasons for it like memory or something else.
[...]

It's likely that something in your program is invoking undefined
behavior, and you're getting results based on, for example, the
contents of memory that you haven't initialized.

The number of ways this can happen probably isn't infinite, but it's
close enough that there's no point in speculating on the cause without
looking at some code.

Try reducing your program down to something much smaller that still
exhibits the problem.

Another approach is to examine the values of variables as your program
is running (either in a debugger or by adding printf calls); it's
likely that some variable will take on a bad value before you see the
symptoms.

But your question is very close to "My program doesn't work; what's
wrong with it?".
 
A

arpit

arpit said:
I had a C application. Which sometimes gives correct result and
some time worng or no result under the same env. Can anyone tell me
what are the possible reasons for it like memory or something else.

[...]

It's likely that something in your program is invoking undefined
behavior, and you're getting results based on, for example, the
contents of memory that you haven't initialized.

The number of ways this can happen probably isn't infinite, but it's
close enough that there's no point in speculating on the cause without
looking at some code.

Try reducing your program down to something much smaller that still
exhibits the problem.

Another approach is to examine the values of variables as your program
is running (either in a debugger or by adding printf calls); it's
likely that some variable will take on a bad value before you see the
symptoms.

But your question is very close to "My program doesn't work; what's
wrong with it?".

--
Keith Thompson (The_Other_Keith) (e-mail address removed) <http://www.ghoti.net/~kst>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"


Well to more clearify the cond.

It is C application which uses A static libarary (VIA std for
gigabit ethernet) The application simply uses the calls of the
library. With that sometimes it is working fine and sometimes did't
work. I run the appliacation in a Cluster.
So now i hope I can expect the possible solutions.As the code is
not that short and with best of my understanding it compiles and links
successfully. well I am using AIX os.
Now suggestions.............

Thanks
 
K

Keith Thompson

arpit said:
arpit said:
I had a C application. Which sometimes gives correct result and
some time worng or no result under the same env. Can anyone tell me
what are the possible reasons for it like memory or something else.

[...]

It's likely that something in your program is invoking undefined
behavior, and you're getting results based on, for example, the
contents of memory that you haven't initialized. [...]
But your question is very close to "My program doesn't work; what's
wrong with it?".

When you post a followup, please trim quoted material that isn't
relevant to your response. In particular, please snip the signature
(the stuff following the "-- " line) unless you're actually commenting
on it.
Well to more clearify the cond.

It is C application which uses A static libarary (VIA std for
gigabit ethernet) The application simply uses the calls of the
library. With that sometimes it is working fine and sometimes did't
work. I run the appliacation in a Cluster.
So now i hope I can expect the possible solutions.As the code is
not that short and with best of my understanding it compiles and links
successfully. well I am using AIX os.
Now suggestions.............

Sorry, that doesn't help.

There are still bazillions of possible causes for the behavior you're
not quite describing, and no possible way for us to guess what the
actual cause might be.

Have you read <http://www.catb.org/~esr/faqs/smart-questions.html>?
 
J

James Kuyper

arpit wrote:
....
It is C application which uses A static libarary (VIA std for
gigabit ethernet) The application simply uses the calls of the
library. With that sometimes it is working fine and sometimes did't
work. I run the appliacation in a Cluster.
So now i hope I can expect the possible solutions.As the code is
not that short and with best of my understanding it compiles and links
successfully. well I am using AIX os.
Now suggestions.............

1. Simplify your program as much as possible, while still demonstrating
the problem. Throw out big chunks of the program at first, and then
throw out smaller parts, until you've finally found the simplest
possible program that demonstrates your problem. You will often find
that in the process of simplifying it you'll figure out what the problem is.

2. Post a message to this newsgroup containing ALL of the following items:
* The COMPLETE text of your simplified program, cut and pasted from your
actual source code file(s). Include any headers you wrote. Do NOT leave
anything out. In my experience, any time someone leaves something out,
it's usually something that is critical for figuring out what the
problem is. By definition, you don't know what the problem is, or you
wouldn't need our help. Therefore you can not be trusted to correctly
identify which parts of your program are irrelevant.

* The exact commands that were used to compile, link, and execute your
program, along with any messages which were generated along the way.

* The full evidence which supports your belief that the program is not
working correctly. If it produces any error messages, show us the full
text of those messages - don't describe them, don't summarize them -
give us the FULL text. If it produces output, and that output is
incorrect, display that output - COMPLETELY.

3. Wait for a response.

We're not mind readers or clairvoyants. We can't help you solve your
problem unless you tell us precisely what it is. We might not be able to
help after you tell us, either, but that's life.
 
C

Christopher Benson-Manica

[comp.lang.c] Keith Thompson said:
It's likely that something in your program is invoking undefined
behavior, and you're getting results based on, for example, the
contents of memory that you haven't initialized.
The number of ways this can happen probably isn't infinite

Depends on your definition of "ways". If

int main() {
int foo[1];
foo[2]=42;
return 0;
}

is distinct from

int main() {
int foo[1];
foo[3]=42;
return 0;
}

, then there an arbitrary number of "ways" on an arbitrary-precision
machine (depending on the range of size_t), although that's still not
infinite. On the other hand, if

int foo() {
}

int main() {
return foo();
}

is distinct from

int bar() {
}

int foo() {
return bar();
}

int main() {
return foo();
}

, then one can write an infinite number of combinations of functions
that eventually invoke a function that produces undefined behavior.
 
P

Paul Sinnett

arpit said:
Hi All,
I had a C application. Which sometimes gives correct result and
some time worng or no result under the same env. Can anyone tell me
what are the possible reasons for it like memory or something else.

Although I think it is a kind of Bug , but i wish to know what are
the factors responsible for the bug that some times it is ok and
sometimes it is problem.

looking for suggestions.

Thanks

Usually such bugs turn out to be due to uninitialised memory. Quite
often uninitialised memory just happens to be zero which has a pretty
good chance of working in many cases. However, on any runs where the
data isn't zero it's likely to fail in unpredictable ways.

A quick way to make the fault repeatable (and therefore easier to track
down) in this case is to have your RTL initialise memory to a usually
bad value like 0xCC. You should be able to find a way to do that in the
documentation for your environment. You might also find that turning up
your warnings will point out the error but if it's legacy code it might
be hidden in the deluge.
 
T

Tor Rustad

arpit said:
Hi All,
I had a C application. Which sometimes gives correct result and
some time worng or no result under the same env. Can anyone tell me
what are the possible reasons for it like memory or something else.

Most likely a bug in the code, but it could also be a HW fault.

Although I think it is a kind of Bug , but i wish to know what are
the factors responsible for the bug that some times it is ok and
sometimes it is problem.

Ill-posted question, can't answer this without speculating.

It could be a side-effect, a race-condition, or a lot of other
possibilities...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top