By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,077 Members | 1,790 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,077 IT Pros & Developers. It's quick & easy.

junk value in variable

P: n/a
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
Nov 14 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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

Nov 14 '05 #2

P: n/a
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

Nov 14 '05 #3

P: n/a
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,
Nov 14 '05 #4

P: n/a
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
Nov 14 '05 #5

P: n/a
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
Nov 14 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.