Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my function pointer code run with no errors?

I have this:

typedef void (*funcptr) (void);

int main(){

    funcptr(); //this can compile and run with no error . WHAT DOES IT MEAN? WHY NO ERRORS?


}
like image 261
Johnyy Avatar asked Dec 01 '22 09:12

Johnyy


1 Answers

The statement creates a funcptr instance by its default constructor* and discard it.

It is just similar to the code

int main () {
    double();
}

(Note: * Technically it performs default-initialization as not all types have constructors. Those types will return the default value (zero-initialized), e.g. 0. See C++98 §5.2.3/2 and §8.5/5 for what actually happens.)

like image 131
kennytm Avatar answered Jan 28 '23 11:01

kennytm