what kind of function arguments iis this ??

G

George Orwell

Sumit said:
start_deamon(THREAD_PER_CONNECTION | USE_DEBUG, port, NULL, NULL, &ace_ech);

You'll understand what follows only if you're familiar with
binary.

The | is C's bitwise OR operator.

A bit can be either 0 or 1. Suppose someone hands you two
bits and asks for the bitwise OR of those two bits. What
they're wanting to know is whether *at least one* of the
two bits is a 1.

If they hand you 0 and 1, then you return a 1 because
the second bit they gave you is a 1.

If they hand you 1 and 0, then you return a 1 because
the first bit they gave you is a 1.

If they hand you 1 and 1, then you return a 1 because
both bits they gave you are 1.

If they hand you 0 and 0, then you return a 0 because
neither of the two bits they gave you is 1.

A brief little truth table would be as follows:

0 | 0 ---> 0
0 | 1 ---> 1
1 | 0 ---> 1
1 | 1 ---> 1

Now we'll extend this to strings of bits. If we want
to find the bitwise OR of, say, 11001101 and 01011100,
we can place one of the strings on top of the other and
perform the bitwise OR operation for each column:

11001101
01011100
--------
11011101

Now, suppose you were to take a string of, say, eight
bits and let each bit act like a tiny switch for some
kind of feature. So if we have the following string
of eight bits:

00101110

We can say that four of those tiny switches are on (1)
and four of those tiny switches are off (0).

Now, let's suppose a program has the following:

#define THREAD_PER_CONNECTION 0x1
#define USE_DEBUG 0x2

We'll stick to eight bits for simplicity. THREAD_PER_CONNECTION
would be

00000001

and USE_DEBUG would be

00000010

If we bitwise OR those two strings together, we get

00000001
00000010
--------
00000011

That result string we get, 00000011, has both of its
switches on. The start_deamon() function ('daemon',
by the way) could look at that result string and
know that the programmer wanted both THREAD_PER_CONNECTION
and USE_DEBUG switched on.

If you have any further questions or need some help with
your threading and networking code, don't hesitate to
let me know, buddy.

Have a wonderful day :)

Yours,
Han from China


Il mittente di questo messaggio|The sender address of this
non corrisponde ad un utente |message is not related to a real
reale ma all'indirizzo fittizio|person but to a fake address of an
di un sistema anonimizzatore |anonymous system
Per maggiori informazioni |For more info
https://www.mixmaster.it
 
N

Nick Keighley

You'll understand what follows only if you're familiar with
binary.

The | is C's bitwise OR operator.

A bit can be either 0 or 1. Suppose someone hands you two
bits and asks for the bitwise OR of those two bits. What
they're wanting to know is whether *at least one* of the
two bits is a 1.

<snip clear, succinct and bullshit free answer>

if only all your posts were like this one!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top