c++ - Meaning of int (*) (int *) = 5 (or any integer value) -


i cannot figure out:

int main() {     int (*) (int *) = 5;     return 0; } 

the above assignment compiles g++ c++11. know int (*) (int *) pointer function accepts (int *) argument , returns int, not understand how equate 5. @ first thought function returns 5 (from recent learning in f#, probably, haha), thought, briefly, function pointer points memory location 5, not work, clearly, , neither hex values.

thinking because function returns int, , assigning int ok (somehow), tried this:

int * (*) (int *) = my_ptr 

where my_ptr of type int *, same type second function pointer, in first case type int. not compile. assigning 5, or int value, instead of my_ptr, doesn't compile function pointer either.

so assignment mean?

update 1

we have confirmation bug, shown in best answer. however, still not known happens value assign function pointer, or happens assignment. (good) explanations on appreciated! please refer edits below more clarity on problem.

edit 1

i using gcc version 4.8.2 (in ubuntu 4.8.2)

edit 2

actually, equating works on compiler. equating std::string variable, or function name returns double, works.

edit 2.1

interestingly, making function pointer function returns data type not pointer, let compile, such as

std::string (*) () = 5.6; 

but function pointer function returns pointer, not compile, such with

some_data_type ** (*) () = any_value; 

it's bug in g++.

 int (*) (int *)  

is type name.

in c++ cannot have declaration type name without identifier.

so compiles g++.

 int (*) (int *) = 5; 

and compiles well:

 int (*) (int *); 

but both invalid declarations.

edit:

t.c. mentions in comments bugzilla bug 60680 similar test case but has not yet been approved. bug confirmed in bugzilla.

edit2:

when 2 declarations above @ file scope g++ correctly issues diagnostic (it fails issue diagnostic @ block scope).

edit3:

i checked , can reproduce issue on latest release of g++ version 4 (4.9.2), latest pre-release version 5 (5.0.1 20150412) , latest experimental version 6 (6.0.0 20150412).


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -