Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

embedded assignment

64 views
Skip to first unread message

ag...@drrob1.com

unread,
Jan 17, 2015, 9:39:37 AM1/17/15
to
I am learning c++ after many years of modula-2. To my eye, assignment
operator is := and equality comparison is =.

In ubuntu 14.04, is there a compiler switch for g++ that flags any
embedded assignment statements. This is to help me when I intend ==
instead of =

Thanks

Öö Tiib

unread,
Jan 17, 2015, 10:09:00 AM1/17/15
to
The g++ gives warning [-Wparentheses] about it with compiler
option -Wall.

g++:
foo.cpp:6:25: warning: suggest parentheses around assignment used as truth value [-Wparentheses]

Also clang does same.
clang:
foo.cpp:6:11: warning: using the result of an assignment as a
condition without parentheses [-Wparentheses]

I am not sure if that is what you asked for.

Alain Ketterlin

unread,
Jan 17, 2015, 10:12:27 AM1/17/15
to
The flag is -Wparentheses but you can use -Wall for a common set of
warning flags, and add -Wextra if you want more.

-- Alain.


Louis Krupp

unread,
Jan 17, 2015, 12:49:53 PM1/17/15
to
I recommend -Werr as well as -Wall. If you can get your code to
compile with no warnings, you don't need to worry about which ones to
fix and which to ignore.

Louis

ag...@drrob1.com

unread,
Jan 17, 2015, 2:04:53 PM1/17/15
to
Thanks guys for your help.

--rob

Jorgen Grahn

unread,
Jan 17, 2015, 2:08:33 PM1/17/15
to
On Sat, 2015-01-17, Louis Krupp wrote:
...
> I recommend -Werr as well as -Wall. If you can get your code to
> compile with no warnings, you don't need to worry about which ones to
> fix and which to ignore.

I recommend /not/ using -Werror. I've lost countless hours/worked
late nights because of it -- an unused function or variable causing a
multi-hour compilation job to abort, when someone desperately neeed
the resulting binary.

The theory is that programmers are like children, and without that
flag you'd have chaos: noone would care about compiler warnings and
there would be thousands of them. I find that cynical: I prefer to
put trust in people, and to believe most want to do a good job, and be
proud of their craftmanship.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

Öö Tiib

unread,
Jan 17, 2015, 6:20:11 PM1/17/15
to
I agree. It is good policy that your code-base produces no warnings.
By such policy compiler warning is minor/cosmetic defect that should
be cheap to fix. Also it is usually simple to see who was its author.
It is pointless to turn a minor defect into show-stopper fault with
-Werr.
Message has been deleted

Scott Lurndal

unread,
Jan 19, 2015, 10:16:54 AM1/19/15
to
And on the lhs, g++ will warn that "statement has no effect".

Öö Tiib

unread,
Jan 19, 2015, 1:38:16 PM1/19/15
to
You mean cases when 'a == b;' is accidentally written instead of 'a = b;' or 'a != b;' is written instead
of 'a = !b;'?
That is [-Wunused-value] also turned on by -Wall.

Message has been deleted
0 new messages