junk value in variable

R

risha

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
 
T

Taran

risha said:
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
 
T

Taran

risha said:
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
 
R

risha

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,
 
C

CBFalconer

risha said:
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.
 
C

CBFalconer

risha said:
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.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top