Is it legal to read data from a function pointer?

According to the standard, is it legal to access data from a function pointer?

Sort of:

#include <stdio.h>

int test(){
    //
}

int main() {
    int (*fp)(void) = &test;

    int i=0;
    for(i; i<10; ++i)
        printf("%x", *(fp+i));
}

Works on ideone , it seems to work - but I wonder if this is expected, or will it be determined by the implementation, and the page can be protected from reading the OS?

+4
source share
2 answers

In terms of C standards, no, it is not.

Appendix J in N1570 contains a chapter on common extensions:

J.5 General extensions

  • The following extensions are widely used in many systems, but not portable for all implementations. The inclusion of any extension that may lead to strict compliance with the program becomes invalid, which makes the implementation mismatch ....

J.5.7. :

  1. void, , (, ) (6.5.4).
+4

.

, undefined, .

10000 , .

-2

All Articles