Unexpected Results

Discussion in 'C Programming' started by arpit, Dec 5, 2007.

  1. arpit

    arpit Guest

    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.

    arpit, Dec 5, 2007
    1. Advertisements

  2. arpit

    Mark Bluemel Guest

    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
    Mark Bluemel, Dec 5, 2007
    1. Advertisements

  3. arpit

    santosh Guest

    Yes the problem is on line 42.
    santosh, Dec 5, 2007
  4. arpit

    CBFalconer Guest

    Correct line 42.
    CBFalconer, Dec 5, 2007
  5. arpit

    Ben Pfaff Guest

    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.
    Ben Pfaff, Dec 5, 2007
  6. [...]

    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

    But your question is very close to "My program doesn't work; what's
    wrong with it?".
    Keith Thompson, Dec 5, 2007
  7. arpit

    arpit Guest

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

    arpit, Dec 6, 2007
  8. 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.
    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>?
    Keith Thompson, Dec 6, 2007
  9. arpit

    James Kuyper Guest

    arpit wrote:
    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.
    James Kuyper, Dec 6, 2007
  10. Depends on your definition of "ways". If

    int main() {
    int foo[1];
    return 0;

    is distinct from

    int main() {
    int foo[1];
    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.
    Christopher Benson-Manica, Dec 6, 2007
  11. arpit

    Paul Sinnett Guest

    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.
    Paul Sinnett, Dec 6, 2007
  12. arpit

    Tor Rustad Guest

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

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

    It could be a side-effect, a race-condition, or a lot of other
    Tor Rustad, Dec 9, 2007
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.