0

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.

3
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by Ancient Dragon
0

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.

0

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.

0

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..

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.