This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

using jb of a unsigned char in c

hello,
I would like to do a bit test of a unsigned char variable. It's like a jb in assembler.

here is my code in c.


unsigned char displ;
unsigned char display3 = 0xA8;
unsigned char i;
sbit display_data = P1^0;

displ = display3;
for (i=0; i<7; i++) {
        if (displ^0 == 1){
        display_data = 0;
        }
        else {
        display_data = 1;
        }
        displ>>=1;
}


I don't have any warning or error, but the result of test is wrong.
is it possible to do in c?

tkx.

Parents
  • I used to detest that K&R style also, but after contracting for so many companies, each invariably with different coding style rules, I've learned to be at peace with whatever as long as it's consistent. For forum posts however, I have adopted the K&R style for the simple reason of conserving vertical space in threads.

    Right now, I'm contracting to the same outfit where the K and the R of K&R work, so guess which brace style I'm using at present. ;-)

Reply
  • I used to detest that K&R style also, but after contracting for so many companies, each invariably with different coding style rules, I've learned to be at peace with whatever as long as it's consistent. For forum posts however, I have adopted the K&R style for the simple reason of conserving vertical space in threads.

    Right now, I'm contracting to the same outfit where the K and the R of K&R work, so guess which brace style I'm using at present. ;-)

Children
  • This is not quite as K&R would have it:

    for (i=0; i<7; i++) {
            if (displ^0 == 1){
            display_data = 0;
            }
            else {
            display_data = 1;
            }
            displ>>=1;
    }
    


    "True" K&R style would be:

    for (i=0; i<7; i++) {
            if (displ^0 == 1){
                    display_data = 0;
            }
            else {
                    display_data = 1;
            }
            displ>>=1;
    }
    


    The "controlled" lines are indented relative to the "controlling" lines.

  • well, fortunately, while we have to adhere to the syntax, we are free to improve on the style.

    I have a lingering suspicion that K&R are, at least partially, responsible for much of the "elegant" C that abounds

    Erik

    PS if anyone does not get that I am fastidious when stating "elegant" the are now told.