1

我想知道所有标准功能的所有地址。但只有wcsstr很奇怪。我无法将其转换或推送为参数来记录地址值。尽管 :

void *address = printf; //OK
void *address = scanf; //OK
void *address = wcsstr; //Compling error!!!

error C2440: 'initializing' : cannot convert from '' to 'void *'

它的定义很奇怪。''定义是什么?也许是“复杂的函数定义???

甚至方法:

printf("Address of wcsstr : 0x%X", wcsstr);

我还发现了疯狂的编译错误:

error C2664: 'printf' : cannot convert parameter 2 from 
'unsigned short *(unsigned short *,const unsigned short *)' to '...'

如何解决这个问题呢?

4

1 回答 1

0

Apart from the conversion being non-standard, you can use a static_cast to select the desired overload of the function.

E.g.

void *address = static_cast<wchar_t const* (*) ( const wchar_t*, const wchar_t* )>( wcsstr );

Or more clear (IMHO),

typedef wchar_t const* Foo( const wchar_t*, const wchar_t* );
void *address = static_cast<Foo*>( wcsstr );

Possibly add a const there, it’s nearly always a good idea… ;-)

于 2013-01-30T06:11:40.177 回答