473,320 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how to let gcc warn me when I use = in conditions

Hi,

Sometimes, I write = instead of == in if conditions by mistakes. Is
there any way the gcc compiler can give me a warning?

Best wishes,
Peng

Nov 15 '05
65 2902

In article <pa****************************@netactive.co.uk> , Lawrence Kirby <lk****@netactive.co.uk> writes:
On Wed, 29 Jun 2005 02:16:37 -0700, websnarf wrote:

if (0 != (a = b)) ...


What advantage does this have over the more readable

if ((a = b) != 0) ...


I don't find this version any "more readable" than Paul's. Do any of
the "readability" proponents have any actual evidence to cite in
support of their argument, or is this merely another case of warring
assumptions?

--
Michael Wojcik mi************@microfocus.com
Nov 15 '05 #51
On 30 Jun 2005 15:41:15 GMT, mw*****@newsguy.com (Michael Wojcik)
wrote:

In article <pa****************************@netactive.co.uk> , Lawrence Kirby <lk****@netactive.co.uk> writes:
On Wed, 29 Jun 2005 02:16:37 -0700, websnarf wrote:
>
> if (0 != (a = b)) ...


What advantage does this have over the more readable

if ((a = b) != 0) ...


I don't find this version any "more readable" than Paul's. Do any of
the "readability" proponents have any actual evidence to cite in
support of their argument, or is this merely another case of warring
assumptions?


In spite of some attempts to quantify it, readability remains a
subjective measure. Therefore, the second version is more readable for
me simply because I tell you it is. As it happens, a lot of people
agree with me.

--
Al Balmer
Balmer Consulting
re************************@att.net
Nov 15 '05 #52
Alan Balmer wrote:
On 30 Jun 2005 15:41:15 GMT, mw*****@newsguy.com (Michael Wojcik)
wrote:

In article <pa****************************@netactive.co.uk> ,
Lawrence Kirby <lk****@netactive.co.uk> writes:
On Wed, 29 Jun 2005 02:16:37 -0700, websnarf wrote:

if (0 != (a = b)) ...

What advantage does this have over the more readable

if ((a = b) != 0) ...


I don't find this version any "more readable" than Paul's. Do any of
the "readability" proponents have any actual evidence to cite in
support of their argument, or is this merely another case of warring
assumptions?


In spite of some attempts to quantify it, readability remains a
subjective measure. Therefore, the second version is more readable for
me simply because I tell you it is. As it happens, a lot of people
agree with me.


While I agree it may be more readable, it think ultimately it depends
*how* you read it.

The first version (to me) read as:
if 0 is not the result of (a = b).

While the latter read as:
if the result of (a = b) is not 0.

I think it's just how you read it?
Nov 15 '05 #53
On Thu, 30 Jun 2005 11:34:55 -0700, in comp.lang.c , Alan Balmer
<al******@att.net> wrote:
In spite of some attempts to quantify it, readability remains a
subjective measure.
Absolutely, though there are some useful metrics,
suchasleavinspacesbetweenletters nOt ranDomLy capitALisIng, and
avoiding with uttermost dexterity the overabundant usage in extremis
of longwinded wittersome and pointlessly extrapolatingly elongeated
word construction paradigms.
Therefore, the second version is more readable for
me simply because I tell you it is.
Horsefeathers.
As it happens, a lot of people
agree with me.


And they're all called Napoleon. Or so the little green men told them.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #54
On Thu, 30 Jun 2005 12:36:07 -0700, in comp.lang.c , "Stan R."
<st*********@bremove.lz.hmrprint.com> wrote:
While I agree it may be more readable, it think ultimately it depends
*how* you read it.

The first version (to me) read as:
if 0 is not the result of (a = b).

While the latter read as:
if the result of (a = b) is not 0.

I think it's just how you read it?


I read them both the same. Which is not entirely unsurprising, since
they *are* both the same.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #55
Lawrence Kirby wrote:
On Wed, 29 Jun 2005 12:10:38 -0700, websnarf wrote:
Lawrence Kirby wrote:
On Wed, 29 Jun 2005 02:16:37 -0700, websnarf wrote:
> if (0 != (a = b)) ...

What advantage does this have over the more readable

if ((a = b) != 0) ...
First of all, its not more readable,


Not for you perhaps, but for some people certainly. Overall that makes it
less readable.


Those two sentences are contradictory.
[...] The trick in question is not general, using it can give you a false
sense of security.
Its generality is not relevant. Its primary use is in catching a lot
of low hanging fruit, which is all you can expect a "saftey convention"
to do anyways. The claim about "false sense of security" is not
credible, and just an assertion that you have no way in hell of backing
up.

If one is using practices such as constant-first comparisons,
commenting switch drop-throughs, testing with maximum compiler warnings
on multiple compilers, running your code through lint and using
semantically reflecting naming conventions then one is more likely to
be alert to safety problems, not assuming a sense of safety that isn't
there.

By *itself* it is an insufficient measure for maximal safety, but using
it does not imply that you not using other mechanisms. That would be
Richard Bos-logic.
[...] Most compilers and failing that checking tools such as lints can
check for this much more reliably, WITHOUT the need to formulate the
code in a less natural way.


If you are compiling to one compiler that specifically covers this,
then that might work for you. But I, personally, have not encountered
one single compiler anywhere that satisfactorily issues all the
warnings I would like it to. So even in the best of circumstances I am
basically giving up some warnings anyways, and == vs = testing in
control code is one of those warnings.

--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/

Nov 15 '05 #56
On Sun, 03 Jul 2005 21:51:18 -0700, websnarf wrote:
Lawrence Kirby wrote:
On Wed, 29 Jun 2005 12:10:38 -0700, websnarf wrote:
> Lawrence Kirby wrote:
>> On Wed, 29 Jun 2005 02:16:37 -0700, websnarf wrote:
>> > if (0 != (a = b)) ...
>>
>> What advantage does this have over the more readable
>>
>> if ((a = b) != 0) ...
>
> First of all, its not more readable,
Not for you perhaps, but for some people certainly. Overall that makes it
less readable.


Those two sentences are contradictory.


Only if you don't expect anybody else to read your code. When there is a
"population" of readers, readability becomes more of a statistical concept.
The fact is that some people find the 0 != form less readable than the !=
0 form. It is certainly possible that for some people the reverse is true,
but I have seen far less evidence of that.
[...] The trick in question is not general, using it can give you a false
sense of security.


Its generality is not relevant. Its primary use is in catching a lot
of low hanging fruit, which is all you can expect a "saftey convention"
to do anyways. The claim about "false sense of security" is not
credible, and just an assertion that you have no way in hell of backing
up.


Not easily, however using a mathod to catch this sort of problem can lead
to a sense of security and where it fails to do so that sense is false.
If one is using practices such as constant-first comparisons,
commenting switch drop-throughs, testing with maximum compiler warnings
on multiple compilers, running your code through lint and using
semantically reflecting naming conventions then one is more likely to
be alert to safety problems, not assuming a sense of safety that isn't
there.
But if you are using compiler warnings then tricks like constant-first
comparisons are pointless since problem cases will be caught anyway, and
much more reliably.
By *itself* it is an insufficient measure for maximal safety, but using
it does not imply that you not using other mechanisms. That would be
Richard Bos-logic.


They are only of any value at all when you are not using other mechanisms.
They don't catch anything that the other mechanisms won't. So the only
time worth considering these tricks is when for whatever reason the other
mechanisms aren't available. 20 years ago these tricks may have had a
legitimate place but times and compilers have moved on.
[...] Most compilers and failing that checking tools such as lints can
check for this much more reliably, WITHOUT the need to formulate the
code in a less natural way.


If you are compiling to one compiler that specifically covers this,
then that might work for you. But I, personally, have not encountered
one single compiler anywhere that satisfactorily issues all the
warnings I would like it to. So even in the best of circumstances I am
basically giving up some warnings anyways, and == vs = testing in
control code is one of those warnings.


If you are honestly saying that the compilers you commonly use don't
support this check and you can't use a lint tool that does then I'm
surprised and will happily concede.

Lawrence

Nov 15 '05 #57
Mark McIntyre <ma**********@spamcop.net> wrote:
On Thu, 30 Jun 2005 11:34:55 -0700, in comp.lang.c , Alan Balmer
<al******@att.net> wrote:
Therefore, the second version is more readable for
me simply because I tell you it is.


Horsefeathers.


So, you would tell Alan that the second version is not, as he says, more
readable to him, because _you_ know better what is readable to _him_
than he himself? What are you, an ergonomist?
As it happens, a lot of people
agree with me.


And they're all called Napoleon. Or so the little green men told them.


At least one of them is called Richard Bos.

Richard
Nov 15 '05 #58
On Sun, 03 Jul 2005 01:11:57 +0100, Mark McIntyre
<ma**********@spamcop.net> wrote:
On Thu, 30 Jun 2005 11:34:55 -0700, in comp.lang.c , Alan Balmer
<al******@att.net> wrote:
In spite of some attempts to quantify it, readability remains a
subjective measure.


Absolutely, though there are some useful metrics,
suchasleavinspacesbetweenletters nOt ranDomLy capitALisIng, and
avoiding with uttermost dexterity the overabundant usage in extremis
of longwinded wittersome and pointlessly extrapolatingly elongeated
word construction paradigms.
Therefore, the second version is more readable for
me simply because I tell you it is.


Horsefeathers.

Hmm... That's amazing. How is it that you know what's more readable to
me, and I, apparently, don't? Do you have any other such insights? I
like chocolate - do you disagree? Am I deluding myself?

--
Al Balmer
Balmer Consulting
re************************@att.net
Nov 15 '05 #59
On Tue, 05 Jul 2005 14:37:37 GMT, in comp.lang.c ,
rl*@hoekstra-uitgeverij.nl (Richard Bos) wrote:
Mark McIntyre <ma**********@spamcop.net> wrote:
On Thu, 30 Jun 2005 11:34:55 -0700, in comp.lang.c , Alan Balmer
<al******@att.net> wrote:
>Therefore, the second version is more readable for
>me simply because I tell you it is.
Horsefeathers.


So, you would tell Alan that the second version is not, as he says, more
readable to him, because _you_ know better what is readable to _him_
than he himself?


Joking aside, its frequently the case that the designer has a better
idea of what the user wants than the user does. How often have the
users told you they actually like how your old software did stuff,
when you know perfectly well that there's a better way and once they
get used to it, they'll be happier.
What are you, an ergonomist?


Did you just call my pint a jessie?
>As it happens, a lot of people agree with me.


And they're all called Napoleon. Or so the little green men told them.


At least one of them is called Richard Bos.


I'm unclear whether you agree with Alan that he knows what he likes,
or that you also like odd ways of writing stuff, or that you're called
napoleon.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #60
On Tue, 05 Jul 2005 11:16:20 -0700, in comp.lang.c , Alan Balmer
<al******@att.net> wrote:
Hmm... That's amazing. How is it that you know what's more readable to
me, and I, apparently, don't?
Come on, get real. How often have you, the software designer, given
users what they *really* want, and ignored what they claimed to want,
because your experience told you that it was merely what they were
used to?
Am I deluding myself?


Almost certainly. Though I refuse to specify what about.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #61
On Tue, 05 Jul 2005 22:43:38 +0100, Mark McIntyre
<ma**********@spamcop.net> wrote:
On Tue, 05 Jul 2005 11:16:20 -0700, in comp.lang.c , Alan Balmer
<al******@att.net> wrote:
Hmm... That's amazing. How is it that you know what's more readable to
me, and I, apparently, don't?
Come on, get real. How often have you, the software designer, given
users what they *really* want, and ignored what they claimed to want,
because your experience told you that it was merely what they were
used to?


Without mentioning my own designs in particular, I suspect that this
happens less often than the reverse, where a software designer builds
something that seems the best way to him, but the customers hate it.
I'm not that much of an egomaniac. I will suggest "improvements", and
even implement them and ask customers to try them for a while, but I
won't be surprised if their idea of how to do their job is better than
mine.

In any case, this isn't the same situation. I have read much code,
including a good many conditionals written backward :-). I've seen
both ways, and I prefer mine. YMMV.
Am I deluding myself?


Almost certainly. Though I refuse to specify what about.


Well, as long as it's not about the chocolate.

--
Al Balmer
Balmer Consulting
re************************@att.net
Nov 15 '05 #62
Mark McIntyre <ma**********@spamcop.net> wrote:
On Tue, 05 Jul 2005 14:37:37 GMT, in comp.lang.c ,
rl*@hoekstra-uitgeverij.nl (Richard Bos) wrote:
Mark McIntyre <ma**********@spamcop.net> wrote:
On Thu, 30 Jun 2005 11:34:55 -0700, in comp.lang.c , Alan Balmer
<al******@att.net> wrote:

>Therefore, the second version is more readable for
>me simply because I tell you it is.

Horsefeathers.


So, you would tell Alan that the second version is not, as he says, more
readable to him, because _you_ know better what is readable to _him_
than he himself?


Joking aside, its frequently the case that the designer has a better
idea of what the user wants than the user does.


We're not talking about a user and a designer here, we're talking about
two (or three) programmers: you, and Alan (and me).
What are you, an ergonomist?


Did you just call my pint a jessie?


No. I called your pint a half of Heineken.
>As it happens, a lot of people agree with me.

And they're all called Napoleon. Or so the little green men told them.


At least one of them is called Richard Bos.


I'm unclear whether you agree with Alan that he knows what he likes,
or that you also like odd ways of writing stuff, or that you're called
napoleon.


I'm sure Alan knows better what he likes than you do, in this case I
agree with Alan in that the second version is more readable to me as
well, and I'm not called Napoleon but Richard Bos.

I make no comments about little green men, because they asked me not to.

Richard
Nov 15 '05 #63
Alan Balmer wrote:
On 27 Jun 2005 02:55:20 -0700, "Rob Thorpe"
<ro***********@antenova.com> wrote:

For example, if you use GNU Emacs and enable cwarn-mode it will
highlight single "=" signs in if-statements in bright red.

This is very useful, but can be irritating if you use them
deliberately.


Another reason not to use them deliberately.


Alternatively, another reason not to use GNU Emacs :-)

Nov 15 '05 #64
Peter Pichler wrote:
Alan Balmer wrote:
On 27 Jun 2005 02:55:20 -0700, "Rob Thorpe"
<ro***********@antenova.com> wrote:

For example, if you use GNU Emacs and enable cwarn-mode it will
highlight single "=" signs in if-statements in bright red.

This is very useful, but can be irritating if you use them
deliberately.

Another reason not to use them deliberately.

Alternatively, another reason not to use GNU Emacs :-)


I like your logic.

Nov 15 '05 #65
Peter Pichler wrote:
Alan Balmer wrote:
On 27 Jun 2005 02:55:20 -0700, "Rob Thorpe"
<ro***********@antenova.com> wrote:

For example, if you use GNU Emacs and enable cwarn-mode it will
highlight single "=" signs in if-statements in bright red.

This is very useful, but can be irritating if you use them
deliberately.


Another reason not to use them deliberately.


Alternatively, another reason not to use GNU Emacs :-)


If you don't like it you don't have to enable it. Just like if you
don't like GNU Emacs you don't have to use it.

Nov 15 '05 #66

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

89
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.