Jump to content
Sign in to follow this  
amohr

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
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...
Sign in to follow this  

×