Anthony
Anthony

Reputation: 631

What does this typecast mean?

The wikipedia entry for Typedef states that in each line after the first line of:

typedef int (*funcptr)(double);         // pointer to function of double returning int
funcptr x = (funcptr) NULL;             // C or C++
funcptr y = funcptr(NULL);              // C or C++
funcptr z = static_cast<funcptr>(NULL); // C++ only

funcptr is used on the left-hand side to declare a variable and is used on the right-hand side to cast a value. Now I understand the second line is casting NULL to funcptr, so x is NULL, but what the heck does the third line mean? If that is supposed to be a cast as the wikipedia entry suggests then why is NULL in parenthesis? I'm not familiar with that type of typecast syntax and am interested in seeing where this is explained.

Upvotes: 1

Views: 125

Answers (1)

Fred Foo
Fred Foo

Reputation: 363817

The third line is C++ syntax, just like the fourth. It means construct a funcptr from NULL, which has the effect as a cast in this case. The comment line stating that this works in C as well is bogus.

Edit: I was about to edit the Wikipedia, but someone beat me to it :)

Upvotes: 5

Related Questions