Jump to content

fairly serious bug when using longs


Recommended Posts

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

Link to post
Share on other sites
  • 3 weeks later...
Guest Pavel

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

Link to post
Share on other sites
  • 1 month later...

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...