Suresh
Suresh

Reputation: 9595

How to disable c++ strong type checking in VS

When porting unix project developed in C language to windows and compiling it with VS 2005, compiler reports errors related to incorrect type conversion like " can not convert 'const char*' to 'char*' ". Is it possible to disable this strong checking through compiler options.

Upvotes: 2

Views: 2272

Answers (3)

Stack Overflow is garbage
Stack Overflow is garbage

Reputation: 247899

Assuming your code is valid C (C89, specifically, since VC++ doesn't support C99), it will be automatically disabled if you either name the file with a .c extension, or in project properties, set it to "Compile as C"

That should disable all C++-specific features and type checks.

Upvotes: 1

Steve Mc
Steve Mc

Reputation: 211

I'm not sure you can - it may be the case that the C code isn't valid (and the Unix compiler you're using incorrectly allows it). You can disable warnings, but I don't think you can disable specific errors.

If you haven't already, you can change the project options to compile as C instead of C++ (Prpoerties -> Config Properties -> C/C++ -> Advanced) but I don't think that'll help.

If you can compile as C++, const_cast might be able to help: http://msdn.microsoft.com/en-us/library/bz6at95h(VS.80).aspx

Upvotes: 0

Goz
Goz

Reputation: 62323

I'm pretty sure, you only need to set the "Compile as C" commandline option (/TP). I'm not entirely familiar with ANSI-C (Over ANSI-C++) but i'd strongly recommend converting it to be type safe regardless. Why return a const and then ignore this fact?

Upvotes: 1

Related Questions