简体   繁体   中英

How to warn about incompatible type for argument on void pointer in C?

In a example below, I want to know the call of func with a wrong type of argument - vptr , which should be called with an int pointer.

void func(int * ptr){
}
int main(){
    void * vptr;
    func(vptr);
}

GCC doesn't warn this type of warnings even with wall option. Is there any other options in gcc, or other programming tricks of finding out those bad manners of codes. Aside that, how about in cpp?

EDIT: VTT answered this is valid in C, but invalid in C++ with no other cast keywords like static_cast ( see the other post in detail ).

In C, it's a valid implicit conversion. In C++, such conversion requires at least static_cast and causes compile-time error otherwise. You should figure out which language are you actually using.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM