I can’t search for | in Google. If you had found it in a software source code that you are trying to interpret, you didn’t know what it does and you couldn’t ask other people for help, how would you find out what it does?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The pipe operator in this case means “use both SWT.APPLICATION_MODAL and SWT.OK as options/flags for my popup box.” It’s a very commonly used idiom with bitfield configuration identifiers, esp. in windowing systems like SWT or Win32.
How it works
The pipe (|) operator is the bitwise OR operator, that is, it computes an OR operation of the two binary integer values. If you check out where APPLICATION_MODAL and OK are defined, you’ll find they are something like this:
When you bitwise OR two (or more) of these numbers together, individual bits will be set for each of the options:
The windowing toolkit that goes to interpret style will be able to tell exactly what you wanted (a popup box that is Modal and has an OK button) by doing a bitwise AND like this:
Kinda clever, in my humble opinion. It allows you to select/represent multiple configuration options in a single variable. The trick is in the integer definitions of the options, and ensuring that they are only powers of 2.