Skip to content
Advertisement

What does “~[]” do?

I saw the following line of code here .

puts("sigprocmask(SIG_UNBLOCK, ~[], []) = 0");

I don’t understand, what does empty array script([]) do?

Also, What is the purpose of ~[] in C?

Advertisement

Answer

The linked program seems to be logging its actions in some invented semi-formalized language. This logging “language” is not C. The string literal in your question is just a line in that invented “language”, which the program will send to standard output. Therefore the ~[] bit has notrhing to do with C and has no special meaning in C context.

After each (supposedly succesful) k_sigprocmask call the progrtam logs that call by sending such strings to the output.

For example, when the program outputs sigprocmask(SIG_SETMASK, [], NULL) = <something> it basically just tells the user “I just called k_sigprocmask function with first argument SIG_SETMASK, empty set of bits as the second argument and a null pointer as the third argument. And I received <something> as the error code.”

[] stands for all-bits-zero bit mask (empty set). [HUP INT QUIT] stands for a mask with only HUP, INT and QUIT bits set to 1. ~[HUP] stands for a mask with all bits set to 1 except HUP bit.

~[] stands for a strange argument value new_set - 1, which does not immediately make sense to me (since new_set is a pointer). I presume it somehow results in a set with all elements included (all bits set to 1).

Advertisement