amohr 0 Posted April 7, 2003 Report Share Posted April 7, 2003 I had to implement a function called get_bit because I couldn't implement it as a macro since the compiler support for longs is so weak. The problem I found is that it's treating the long parameter as a reference! Which means that if I modify the parameter value in the function it's reflected in the caller's copy...i.e. char get_bit(unsigned long x, char y) { char i; for(i=0; i<y; i++) x >>= 1; x &= 1; return x; } long i = 1; // i == 1 get_bit(i, 2); // i now == 0 !!! eeeeeeeee Quote Link to post Share on other sites
Guest Pavel Posted April 22, 2003 Report Share Posted April 22, 2003 Can't reproduce the problem. The variable does not get changed in caller. If you still see this problem send me a zipped projects and descriptions what to do to reproduce it. Regards, Pavel Quote Link to post Share on other sites
QBall 0 Posted June 6, 2003 Report Share Posted June 6, 2003 shouldn't you cast the variable x to a char? your returnvalue is a char, but the value x is unsigned long. Regards, Pim Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.