user697683
user697683

Reputation: 1483

Is there a gcc flag to allow C-style implicit pointer conversions in C++?

I'm drowning in the sea of casts between char* and unsigned char*, it's just ridiculous. There has to be some way around this.

Upvotes: 1

Views: 1461

Answers (2)

plugwash
plugwash

Reputation: 10504

Yes -fpermissive will allow this

Upvotes: 3

Ryan Haining
Ryan Haining

Reputation: 36802

No. C++ pointers are more strongly typed than C's. You are required to cast between pointer types outside of upcasting in C++ which can happen implicitly. What you want is intentionally difficult in C++ to discourage people from doing so.

C allows these potentially unsafe conversions to occur silently, but if you enable warnings in gcc, the issues will be brought to your attention. On another note: having a char * point to an unsigned char is well defined behavior, though could be error prone in the long run depending on how the memory is used.

Upvotes: 0

Related Questions