Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding of C programming syntax [duplicate]

Tags:

c

i came across this syntax and i am not able to know how to start understanding this.

How to start decoding of such piece of c programming code.

(*(void(*)())0)();

i have tried to compile this code and it compile without any warning or error. SO it seems valid syntax of c programming.

like image 612
Jeegar Patel Avatar asked Dec 20 '15 06:12

Jeegar Patel


People also ask

What Is syntax of C programming?

The syntax of the C programming language is the set of rules governing writing of software in the C language. It is designed to allow for programs that are extremely terse, have a close relationship with the resulting object code, and yet provide relatively high-level data abstraction.

What double means in C?

A double is a data type in C language that stores high-precision floating-point data or numbers in computer memory. It is called double data type because it can hold the double size of data compared to the float data type. A double has 8 bytes, which is equal to 64 bits in size.


1 Answers

Break it as follows:

  • (void(*)()) represents a cast of 0. Here its is a pointer to a function with return type void and can have any number of arguments.

       (  void  (*)  ( )  )
           ^     ^    ^
           |     |    |
           |     |    |
           |     |    |
           |     |    |
           +     |    +
    Return type  |    Function
                 |
              Pointer
    
  • *(void(*)())0 is dereferencing the address 0x00000000. I think its a function address there.

  • (*(void(*)())0)(); call the function.

like image 160
haccks Avatar answered Oct 08 '22 09:10

haccks