junk value in variable

Discussion in 'C Programming' started by risha, Apr 5, 2005.

  1. risha

    risha Guest

    void FlashReadM(volatile unsigned long *fl_ad,unsigned long abb)
    {
    unsigned long ulvald;
    abb=2;
    ulvald=0;
    //fl_ad=(volatile unsigned long *)0x8020;
    ulvald= *(fl_ad);
    //return ucVal;
    }

    in the above prg the value of abb is shown as 2 but the value of
    ulvald does not show 0 it shows a junk value in the debugger memeory
    window
    risha, Apr 5, 2005
    #1
    1. Advertising

  2. risha

    Taran Guest

    risha wrote:
    > void FlashReadM(volatile unsigned long *fl_ad,unsigned long abb)
    > {
    > unsigned long ulvald;
    > abb=2;
    > ulvald=0;
    > //fl_ad=(volatile unsigned long *)0x8020;
    > ulvald= *(fl_ad);


    what if fl_ad is NULL? check for ptr==Null before dereferencing.

    you have updated the value of ulvald with the value @ fl_ad. Why should
    it should show 0?

    > //return ucVal;
    > }
    >
    > in the above prg the value of abb is shown as 2 but the value of
    > ulvald does not show 0 it shows a junk value in the debugger memeory
    > window


    Why should it be junk value? You are passing a pointer to FlashReadM,
    so my assumption is that you want to read the value at location pointed
    to by fl_ad, which must not be junk or else why read it?

    Its junk to you beacuase you expect 0, but it would probably certianly
    make sense for the FlashReadM! Ask Him.

    HTH
    --
    Taran
    Taran, Apr 5, 2005
    #2
    1. Advertising

  3. risha

    Taran Guest

    risha wrote:
    > void FlashReadM(volatile unsigned long *fl_ad,unsigned long abb)
    > {
    > unsigned long ulvald;
    > abb=2;
    > ulvald=0;
    > //fl_ad=(volatile unsigned long *)0x8020;
    > ulvald= *(fl_ad);


    what if fl_ad is NULL? check for ptr==Null before dereferencing.

    you have updated the value of ulvald with the value @ fl_ad. Why should
    it should show 0?

    > //return ucVal;
    > }
    >
    > in the above prg the value of abb is shown as 2 but the value of
    > ulvald does not show 0 it shows a junk value in the debugger memeory
    > window


    Why should it be junk value? You are passing a pointer to FlashReadM,
    so my assumption is that you want to read the value at location pointed
    to by fl_ad, which must not be junk or else why read it?

    Its junk to you beacuase you expect 0, but it would probably certianly
    make sense for the FlashReadM! Ask Him.

    HTH
    --
    Taran
    Taran, Apr 5, 2005
    #3
  4. risha

    risha Guest

    Thank u for the reply sir. But the mistake lies on my part in not
    making things clear. For conveinence I have numbered the prm
    statements.

    1.void FlashReadM(volatile unsigned long *fl_ad,unsigned long abb)
    {
    2. unsigned long ulvald;
    3. abb=2;
    4. ulvald=0;
    5. //fl_ad=(volatile unsigned long *)0x8020;
    6. ulvald = *(fl_ad);
    7. return ulvald;
    }
    *******************************************************************
    1>My question is in line #4 the varaible ulvald is assigned 0 after
    line #4 is executed it should have initialzed the variable ulvald as 0
    at this point.
    (memory in the debugger window indicates junk value)

    2>When it reaches line #6 it should now load the value which is at
    address location fl_ad which has the value passed as a parameter in
    the function.The value at that location here in my case 0x8020 has
    value 0x03.After the execution of line #6 in the debugger window for
    memory it should indicate the new value atleast but here it neither
    shows 0 in the beginnning nor 3 as the value.So it is junk value
    again!!!


    3>"what if fl_ad is NULL? check for ptr==Null before dereferencing."
    The debugger indicates the correct address 0x8020.Hence not null.

    4>so my assumption is that you want to read the value at location
    pointed
    to by fl_ad,

    Absolutely right sir thats what I am trying to do.

    Probably since it did not even initiaze i think something is really
    wrong here....

    I am a student and any help will do me good,(sorry for the long
    message)
    Thanks in advance,
    risha, Apr 7, 2005
    #4
  5. risha

    CBFalconer Guest

    risha wrote:
    >
    > Thank u for the reply sir. But the mistake lies on my part in not
    > making things clear. For conveinence I have numbered the prm
    > statements.
    >
    > 1.void FlashReadM(volatile unsigned long *fl_ad,unsigned long abb) {
    > 2. unsigned long ulvald;
    > 3. abb=2;
    > 4. ulvald=0;
    > 5. //fl_ad=(volatile unsigned long *)0x8020;
    > 6. ulvald = *(fl_ad);
    > 7. return ulvald;
    > }
    > *******************************************************************
    > 1> My question is in line #4 the varaible ulvald is assigned 0 after
    > line #4 is executed it should have initialzed the variable ulvald as
    > 0 at this point. (memory in the debugger window indicates junk value)


    What sort of optimization is the compiler doing? There is no
    reason for it to generate any code for line 4, because that value
    is never used, and is immediately overwritten by line 6.

    BTW, please DO NOT use nuisance abbreviations such as 'u' or
    'prm'. They only serve to make your article hard to read and to
    annoy.

    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
    CBFalconer, Apr 7, 2005
    #5
  6. risha

    CBFalconer Guest

    risha wrote:
    >
    > Thank u for the reply sir. But the mistake lies on my part in not
    > making things clear. For conveinence I have numbered the prm
    > statements.
    >
    > 1.void FlashReadM(volatile unsigned long *fl_ad,unsigned long abb) {
    > 2. unsigned long ulvald;
    > 3. abb=2;
    > 4. ulvald=0;
    > 5. //fl_ad=(volatile unsigned long *)0x8020;
    > 6. ulvald = *(fl_ad);
    > 7. return ulvald;
    > }
    > *******************************************************************
    > 1> My question is in line #4 the varaible ulvald is assigned 0 after
    > line #4 is executed it should have initialzed the variable ulvald as
    > 0 at this point. (memory in the debugger window indicates junk value)


    What sort of optimization is the compiler doing? There is no
    reason for it to generate any code for line 4, because that value
    is never used, and is immediately overwritten by line 6.

    BTW, please DO NOT use nuisance abbreviations such as 'u' or
    'prm'. They only serve to make your article hard to read and to
    annoy.

    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
    CBFalconer, Apr 7, 2005
    #6
    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. Peter Row
    Replies:
    0
    Views:
    290
    Peter Row
    Mar 3, 2004
  2. =?Utf-8?B?TEFDSA==?=

    Re: SmtpMail - Hotmail Junk e-mail

    =?Utf-8?B?TEFDSA==?=, Sep 16, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    442
    =?Utf-8?B?TEFDSA==?=
    Sep 16, 2004
  3. =?Utf-8?B?TEFDSA==?=

    Re: SmtpMail - Hotmail Junk e-mail

    =?Utf-8?B?TEFDSA==?=, Sep 24, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    481
    =?Utf-8?B?TEFDSA==?=
    Sep 24, 2004
  4. Denzil
    Replies:
    1
    Views:
    771
    John Harrison
    Jul 15, 2004
  5. Pradeep
    Replies:
    1
    Views:
    311
    Tim Love
    Dec 20, 2007
Loading...

Share This Page