Strange behavior, initialize function pointer with int?

By chance, I found this code to compile on VS2012.

typedef void (*func)();
func f = func(12);

finitialized with the integer 12 as its address. as far as I know, an action with an integer on a function pointer really does look like this:

func f = (func)12;

while the statement is func(12)more like a constructor, so I tried this:

func f(12);

and failed to compile.


func f = (func)12  //ok, cast           1
func f = func(12); //ok, what?          2
func f(12);        //failed             3
func f = 12;       //failed             4

so my question is:

  • What is the real basic syntax func(12), is listing or initialization?
  • How to initialize a pointer to a function with an integer?
  • Should compilation of the 4th expression? What about the third?
+4
1

:

func f = (func)12  //ok, cast           1

12 , . , , ++ reinterpret_cast . .

func f = func(12); //ok, what?          2

. (type) value type(value) , type .

func f(12);        //failed             3

func, 12. ,

  • , (; func )
  • , ( , ).

.

func f = 12;       //failed             4

, ( ) , ( , , ). .

, !

+3

All Articles