0

Possible Duplicate:
What is “:-!!” in C code?

The linux kernel module_param() macro expands into several instructions, some of them using numbers (sizes) that are calculated as follow (I only paste here relevant code):

sizeof(struct { int:- ! !(((00400|00040|00004)) < 0 || ((00400|00040|00004)) > 0777 || (((00400|00040|00004)) & 2)); })

Could somebody enlighten me what is that int:- ! !(NUMBER) doing?

Actually, I have several questions: 1) why define a struct with a single member? 2) why do not name that member? (or is the member's name... "int", just like the type?) 3) what is the meaning of that int:- ! !(NUMBER) expression? Is that a struct field? A bitfield? 4) what is the meaning and the final result of the above sizeof()?

Thank you very much.

Community
  • 1
  • 1
user1284631
  • 4,446
  • 36
  • 61
  • 2
    It's an anonymous bit field. – Kerrek SB Nov 23 '12 at 14:43
  • 1
    it's a compile time check your questions are answered here [What is “:-!!” in C code?](http://stackoverflow.com/questions/9229601/what-is-in-c-code) – iabdalkader Nov 23 '12 at 14:52
  • 1
    Pondering the meaning of this obfuscated code is most likely a big waste of time. To sum it up: it is a very disturbed person's way of implementing `static_assert` using bitwise operators on octal numbers, while relying on non-standard, gcc-specific features. – Lundin Nov 23 '12 at 14:54
  • @Lundin `static_assert` ? isn't that c++11 ? – iabdalkader Nov 23 '12 at 15:01
  • What is this non-standard, please? @Lundin – alk Nov 23 '12 at 15:06
  • @mux: Thank You, please post an answer in order for me to accept it. – user1284631 Nov 23 '12 at 15:09
  • @Lundin: I need to understand what the code does as one of my static analysis tools does not, so I have to manually correct that. – user1284631 Nov 23 '12 at 15:10
  • @axeoth there's no need to duplicate an answer, the question linked has plenty of good answers and comments :) – iabdalkader Nov 23 '12 at 15:10
  • @axeoth Since the code is a complete mess and also relies on non-standard C, it will not pass any half-decent static analysis tool. – Lundin Nov 26 '12 at 07:20

0 Answers0