If I have these function variables:

int (*f)(int);
int (*g)(int);
int (*h)(char);

why can I do the assingment f=g but if I do h=g the C compiler gives me warning while the C++ compiler gives me an error.
Can any one please explain this to me.

Didn't you post the same topic before? The answer is like two pages behind. h is char but g is int. they are not of the same type.

Didn't you post the same topic before? The answer is like two pages behind. h is char but g is int. they are not of the same type.

Yes I did but I'm trying to get at why the C compiler gives only a warning while a C++ gives an error.

I think it is because C is just more flexible when it comes to handling memory.. hence giving your more control over it.


[edit] Another thing I can think of is that char is one byte while int is four. C++ compiler probably catches that as an error to prevent such assignment. but since C is naturally more flexible with memory/pointer, it's just an error? Well, maybe I'm just talking out of my ass..

C and C++ are not the same language, so don't expect C compilers to act the same as c++. There are many differences that you will encounter.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.