How to Force compiler to give error notice in "if" clause?

G

Guest

Hi,

Is there a way to force Visual C++ compiler (VS 2003) to give an error or
notice in case of IF statment have "=" instead of "=="

for example
if(locationID = 10351) is passing, but I want an error fired

Thanks
Milan
 
M

Marcus Heege

warning C4706 (assignment within conditional expression) can report the
problem you describe.

Since it is a level 4 warning, you can see this warning if you compile with
/W4.
To see this elevate this warning to a level 1 warning, you can use /w14703.
To treat this warning as en error you can use /we4703

Marcus
 
B

Bruno van Dooren

Since it is a level 4 warning, you can see this warning if you compile
with /W4.
To see this elevate this warning to a level 1 warning, you can use
/w14703.
To treat this warning as en error you can use /we4703

Additionally, if you go to your project properties, then to configuration
properties -> C++ -> general
you can set the global warning level, and the global 'treat warnings as
errors' flag.

I have recently taken to compile all new projects with /W4 and all warnings
treated as error.
This way I can avoid typo bugs like the one you mentioned.

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 
G

Guest

MB- [Sat, 29 Apr 2006 08:40:02 -0700]:
if(locationID = 10351) is passing, but I want an error fired

Use (or rather, don't)

if (10351 = locationID)

and you won't have to worry about it. Try
it, you'll like it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top