Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deprecated casts in C++

I am using Code::Blocks for learning C++. Consider the following code:

C

#include <iostream>
using namespace std;

int main(int argc, char** argv)
{
    const int i = 0;
    int* j = (int*)&i;
}

The cast I have used in the above program has been deprecated in C++ (if I'm correct about this), but was followed in C. The Code::Blocks IDE doesn't show me any warning for this code. I know that C++ supports the explicit casts such as const_cast, static_cast, etc.

My question is: Are there any free IDE available on the internet that show warning for such deprecated syntax?

like image 956
Sumit Gera Avatar asked Dec 11 '22 18:12

Sumit Gera


1 Answers

I'm assuming CodeBlocks is compiling using gcc. You can enable a warning by adding the compiler flag -Wold-style-cast. You might have to poke around in CodeBlocks to figure out where to put that flag. You can also enable a bunch more warnings with -Wall.

like image 194
yiding Avatar answered Dec 24 '22 03:12

yiding