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.

    Thanks
    arpit, Dec 5, 2007
    #1
    1. Advertising

  2. arpit

    Mark Bluemel Guest

    arpit wrote:
    > 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>".
    Mark Bluemel, Dec 5, 2007
    #2
    1. Advertising

  3. arpit

    santosh Guest

    arpit wrote:

    >
    > 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.
    santosh, Dec 5, 2007
    #3
  4. arpit

    CBFalconer Guest

    arpit wrote:
    >
    > 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.

    --
    Chuck F (cbfalconer at maineline dot net)
    <http://cbfalconer.home.att.net>
    Try the download section.



    --
    Posted via a free Usenet account from http://www.teranews.com
    CBFalconer, Dec 5, 2007
    #4
  5. arpit

    Ben Pfaff Guest

    arpit <> writes:

    > 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.
    --
    Ben Pfaff
    http://benpfaff.org
    Ben Pfaff, Dec 5, 2007
    #5
  6. arpit <> writes:
    > 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) <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"
    Keith Thompson, Dec 5, 2007
    #6
  7. arpit

    arpit Guest

    On Dec 6, 3:32 am, Keith Thompson <> wrote:
    > arpit <> writes:
    > > 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) <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
    arpit, Dec 6, 2007
    #7
  8. arpit <> writes:
    > On Dec 6, 3:32 am, Keith Thompson <> wrote:
    >> arpit <> writes:
    >> > 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>?

    --
    Keith Thompson (The_Other_Keith) <>
    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"
    Keith Thompson, Dec 6, 2007
    #8
  9. arpit

    James Kuyper Guest

    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.
    James Kuyper, Dec 6, 2007
    #9
  10. [comp.lang.c] Keith Thompson <> wrote:

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

    --
    C. Benson Manica | I appreciate all corrections, polite or otherwise.
    cbmanica(at)gmail.com |
    ----------------------| I do not currently read any posts posted through
    sdf.lonestar.org | Google groups, due to rampant unchecked spam.
    Christopher Benson-Manica, Dec 6, 2007
    #10
  11. arpit

    Paul Sinnett Guest

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

    Tor Rustad Guest

    arpit wrote:
    > 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...

    --
    Tor < | tr i-za-h a-z>
    Tor Rustad, Dec 9, 2007
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott Lander

    Re: unexpected results

    Scott Lander, Jul 7, 2003, in forum: Perl
    Replies:
    0
    Views:
    1,731
    Scott Lander
    Jul 7, 2003
  2. Dave
    Replies:
    1
    Views:
    334
    Leor Zolman
    Apr 8, 2004
  3. =?Utf-8?B?QXJ0?=

    Page inherting from .master - unexpected results

    =?Utf-8?B?QXJ0?=, May 26, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    355
    =?Utf-8?B?QXJ0?=
    May 26, 2006
  4. CK
    Replies:
    3
    Views:
    316
  5. Steven D'Aprano

    Unexpected timing results

    Steven D'Aprano, Feb 23, 2006, in forum: Python
    Replies:
    7
    Views:
    391
    Steven D'Aprano
    Feb 24, 2006
Loading...

Share This Page