When dereferencing and subsequent incrementing of a pointer to a function pointer, what happens first?

Given this code:

 typedef void (*Thunk)();
 Thunk* gFP;

 void foo(){ printf("Foo "); *gFP(); };
 void bar(){ printf("Bar ");

 Thunk Codex[] = { foo, bar };

 gFP = Codex;

 (*gFP++)();

Does the function call before or after the increment?
ie: will it print "Foo Foo Foo ..." or "Foo Bar"?

+3
source share
3 answers

This is just my personal opinion. I am not 100% sure that this is correct. So please forgive me if my answer is wrong.

C99 6.5.2.2/10 Function calls say:

The evaluation order of the function designation, the actual arguments and the subexpressions inside the actual arguments are not defined, but there is a sequence point in front of the actual call.

C99 6.5.2.4/2 Postfix increment and decrement operators say:

.

post increment - . f( x ), , f x , . , gFP++ , , Foo Bar.

Edit: -C C99 ++ C99.
, .

+4

. , -: .

., ,

, , , foo() foo() bar().

http://newsgroups.derkeiler.com/Archive/Comp/comp.std.c/2009-10/msg00053.html - comp.std.c " ", . , , .

undefined.

, C , , - , ( f(i++) + g(j++) i g() j f() undefined.)

6.5.5.2 (p 10) :

, .

, ++.

+1

C.

gFP++ , *gFP

, .

So, in the end, you get a gFP validity point, then a function call, then the gFP value will be increased.

So you are done stack overflow.

0
source

Source: https://habr.com/ru/post/1794521/


All Articles