Re: [piclist] Parameters not passing correctly


Jun 30, 2008

 


----------------------------

#10792 Jun 30, 2008

I am writing a program for the PIC18F66J50, using MPLAB IDE v8.14

(also happened with 8.10). Suddenly I noticed one of my functions

was not working correctly, and discovered that inside the function

the parameters that were passed in do not have the values that was

used in the function call. I made a test function (see below) and

the same thing happens.



void main()

{

...

ServiceDebugPrint();

...

}



void ServiceDebugPrint()

{

...

Test( 1, 2.0 ); //breakpoint here

...

}



void Test( unsigned char a, float b )

{

unsigned char c = 0;

unsigned char d = 0;

unsigned char e = 0;

c = 1;

d = 2;

e = 3;

c = d;

d = e;

e = c;

}.



When I step through the function, the watch window shows the

following values:

a = 0x00

b = 2.298970e-041

These values are the same every time I run the program.



If I reverse the order of the arguments (change to "unsigned char a,

float b") the values become:

a = 0x16

b = 8.968310e-044



It is not a matter of the name "Test", if I use a different name the

same thing happens.



IMPORTANT CLUE: If I call Test() as the first line of main(), the

parameters are passed correctly.



It's like I'm running out of RAM or stack space. Any ideas what's

going on here?



Thanks

BasicPoke



----------------------------

#10797 Jul 1, 2008

Are you sure this isn't a vagary of MPLAB, what does the assembler code look like?



This would show you if it is going off into cyber silicon.



Even better, if possible disassemble the hex file and and check something hasn't altered during the conversion phase.



Colin



:: am writing a program for the PIC18F66J50, using MPLAB IDE v8.14

:: (also happened with 8.10). Suddenly I noticed one of my functions

:: was not working correctly, and discovered that inside the function

:: the parameters that were passed in do not have the values that was

:: used in the function call. I made a test function (see below) and

:: the same thing happens.

::

:: void main()

:: {

:: ..

:: ServiceDebugPrint();

:: ..

:: }

::

:: void ServiceDebugPrint()

:: {

:: ..

:: Test( 1, 2.0 ); //breakpoint here

:: ..

:: }

::

:: void Test( unsigned char a, float b )

:: {

:: unsigned char c = 0;

:: unsigned char d = 0;

:: unsigned char e = 0;

:: c = 1;

:: d = 2;

:: e = 3;

:: c = d;

:: d = e;

:: e = c;

:: }

::

:: When I step through the function, the watch window shows the

:: following values:

:: a = 0x00

:: b = 2.298970e-041

:: These values are the same every time I run the program.

::

:: If I reverse the order of the arguments (change to "unsigned char

:: a,

:: float b") the values become:

:: a = 0x16

:: b = 8.968310e-044

::

:: It is not a matter of the name "Test", if I use a different name

:: the

:: same thing happens.

::

:: IMPORTANT CLUE: If I call Test() as the first line of main(), the

:: parameters are passed correctly.

::

:: It's like I'm running out of RAM or stack space. Any ideas what's

:: going on here?

::

:: Thanks

:: BasicPoke

--

cdb, colin@... on 2/07/2008



Web presence: www.btech-online.co.uk



Hosted by: www.1and1.co.uk/?k_id=7988359


S
e
n
i
o
r
T
u
b
e
.
o
r
g