example 11-2:
page 177:
the question:
the HIGH_SPEED flag works, but the DIRECT_CONNECT flag does not. Why?
I could see when i was typing it that you cant shift by more than 7 bits, and quite rightly expected the program to output:
High speed set
But for some reason i get:
guyattc2-practical_c3-> high
High speed set
Direct connect set
Can anyone tell me if ive copied it wrong or if there is an error. id like to know why my program works (bet thats a new one)
Any help much appreciated, thanks.Code:#include <stdio.h> const int HIGH_SPEED = (1<<7); /* modem is running fast */ /* we are using a hardwired connection */ const int DIRECT_CONNECT = (1<<8); char flags = 0; /* start with nothing */ int main() { flags |= HIGH_SPEED; /* we are running fast */ flags |= DIRECT_CONNECT; /*beacuse we are wired together */ if((flags & HIGH_SPEED) != 0) { printf("High speed set\n"); } if((flags & DIRECT_CONNECT) != 0) { printf("Direct connect set\n"); } return(0); }
--CHriS



LinkBack URL
About LinkBacks
)




im back at home. was working on this at uni. but yeah i can see all your points now. hopefully it should all be good. although matey, you said your output was both... or did you mean that?! (sorry ive had a long day... its hard being a student hehe)