Andy Pugh wrote:
On 24 June 2010 13:39, Kenneth Lerman <[email protected]> wrote:

==========
static PmCartesian old;
double dx = 0, dy = 0, C = 0;
double fKcount = 0, rKcount = 0;
==========
"static" means that this variable will be visible only from this file.
The lack of the static keyword means that dx, dy, C, fKcount, and rKcount
will be visible from other files.

Isn't that only the case if the other files "Extern" it? I can
definitely see the scop for that being a problem with dx and dy, but
the timing would have to be very accurate for it to explain the
rKcount behaviour, which increases by exactly 0.7101..... every time
the function is called.

No. The modern ANSI C  lets you:

f1.c:
---
int a = 1;
---

f2.c
--
int a;
--

This is sometimes referred to the "COMMON" model of storage by analogy with the FORTRAN usage. In the above example, the variable 'a' may only be initialized in one of the locations.
That probably isn't what you want since it means that some other function
might be changing those variables.

I think perhaps I should print the values of both and see if the
problem is in the actual value of tKcount, or somewhere in the
transfer of that value to the HAL pin.

(I don't actually need or use rKcount, but it seems to be indicative
of a wider problem, ie variables not taking on anything like the
expected values. I am still baffled that removing a line that had no
link at all to the (unrelated) stepgen function stopped the bizarre
drift in the -fb value. )

Even if that isn't the problem, you should probably declare those variables static so that future readers of the code don't have to go looking to find out where else the variables might be used or changed.

Ken

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to