linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Booleans, what a wonderful type!
@ 2007-07-18  1:43 ricknu-0
  2007-07-18  2:19 ` Al Viro
  2007-07-18  2:25 ` Al Viro
  0 siblings, 2 replies; 8+ messages in thread
From: ricknu-0 @ 2007-07-18  1:43 UTC (permalink / raw)
  To: linux-sparse

Good morning to you all!

As most of you do not know, I am on Google's SoC
<http://code.google.com/soc/2007/sparse/appinfo.html?csaid=CB0974F67B64AD0C> to
add the ability to suggestions when booleans could/should be used.

Unforunatly, you need both a working internet connection and computer to work on
this, which I now appriciate how difficult it can be to manage, otherwise this
would have been sent _much_ earlier.


Anyhow, I would like any and all ideas on these:

* Should it make all the suggestions at the "same time" or should it first just
suggest the "source" of the boolean-change and then, when converted, suggest the
"users" of the source to change over?

* Should it really be handled by a -W-flag? After all, it is more of a
suggestion then a warning.


... and some questions:

* Most likly a _really_ stupid newbie question, but I have seen several of this
form:
<function>
{
        <variable> a;
        <doing something useful (no sign of 'a')>
        a = <some value/variable>;
        <exit>
}
How is this variable useful?

* Why is there no va_end() after va_start()?

According to the manual (STDARG(3)):
va_end
       Each invocation of va_start() must be matched by a corresponding  invo-
       cation  of va_end() in the same function. After the call va_end(ap) the
       variable ap is undefined.  Multiple  transversals  of  the  list,  each
       bracketed  by  va_start() and va_end() are possible.  va_end() may be a
       macro or a function.


* Is there any advantage of "for (;;)" instead of ex "while (true)"?

* Why is it written in C and not C++. Easier access to kernel-developers? (just
curious)


Have a good night.
Richard Knutsson

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Booleans, what a wonderful type!
  2007-07-18  1:43 Booleans, what a wonderful type! ricknu-0
@ 2007-07-18  2:19 ` Al Viro
  2007-07-18  2:40   ` Brett Nash
  2007-07-18 16:33   ` Josh Triplett
  2007-07-18  2:25 ` Al Viro
  1 sibling, 2 replies; 8+ messages in thread
From: Al Viro @ 2007-07-18  2:19 UTC (permalink / raw)
  To: ricknu-0; +Cc: linux-sparse

On Wed, Jul 18, 2007 at 03:43:39AM +0200, ricknu-0@student.ltu.se wrote:
 
> * Most likly a _really_ stupid newbie question, but I have seen several of this
> form:
> <function>
> {
>         <variable> a;
>         <doing something useful (no sign of 'a')>
>         a = <some value/variable>;
>         <exit>
> }
> How is this variable useful?

Explain, please.  If you mean moving the declaration down - it's not
idiomatic in C and frankly, C++ style tends to make declarations harder
to find when you read the code.
 
> * Why is there no va_end() after va_start()?

Where?

> According to the manual (STDARG(3)):
> va_end
>        Each invocation of va_start() must be matched by a corresponding  invo-
>        cation  of va_end() in the same function. After the call va_end(ap) the
>        variable ap is undefined.  Multiple  transversals  of  the  list,  each
>        bracketed  by  va_start() and va_end() are possible.  va_end() may be a
>        macro or a function.

Yes, and AFAICS uses of va_start()/va_end() in sparse are correct.  If you
see any broken one - yell.

> * Is there any advantage of "for (;;)" instead of ex "while (true)"?

It's more idiomatic and faster recognized by readers.  while (1) is also
quite common; while (true) will be understood, but will distract since it
will take more conscious effort to recognize.
 
> * Why is it written in C and not C++. Easier access to kernel-developers? (just
> curious)

Generally saner language?  Turn the question around - what in sparse would
be inherently cleaner in C++?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Booleans, what a wonderful type!
  2007-07-18  1:43 Booleans, what a wonderful type! ricknu-0
  2007-07-18  2:19 ` Al Viro
@ 2007-07-18  2:25 ` Al Viro
  2007-07-19  0:38   ` ricknu-0
  1 sibling, 1 reply; 8+ messages in thread
From: Al Viro @ 2007-07-18  2:25 UTC (permalink / raw)
  To: ricknu-0; +Cc: linux-sparse

On Wed, Jul 18, 2007 at 03:43:39AM +0200, ricknu-0@student.ltu.se wrote:
> Good morning to you all!
> 
> As most of you do not know, I am on Google's SoC
> <http://code.google.com/soc/2007/sparse/appinfo.html?csaid=CB0974F67B64AD0C> to
> add the ability to suggestions when booleans could/should be used.

Er...  Of _course_ booleans are values.  And yes, you can say true + false.
Guaranteed to evaluate to int, value of expression being 1.  It's perfectly
correct C99.  Same as true + true is guaranteed to be 2 (int, again); assigning
that to _Bool variable is guaranteed to give 1, aka true (see the rules
for conversion to _Bool).

Now, sparse handling of _Bool sucks in quite a few places (e.g. conversion
to it is not reduction modulo 2, it's comparison with 0), but I wonder if
that's what you have in mind...

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Booleans, what a wonderful type!
  2007-07-18  2:19 ` Al Viro
@ 2007-07-18  2:40   ` Brett Nash
  2007-07-18 16:33   ` Josh Triplett
  1 sibling, 0 replies; 8+ messages in thread
From: Brett Nash @ 2007-07-18  2:40 UTC (permalink / raw)
  To: Al Viro; +Cc: ricknu-0, linux-sparse

On Wed, 2007-07-18 at 03:19 +0100, Al Viro wrote:

> Yes, and AFAICS uses of va_start()/va_end() in sparse are correct.  If you
> see any broken one - yell.

As an aside; how hard is to get sparse to check for this?

Would the general lock structure do enough with the right declaration of
va_start/va_end?   

	Regards,
	nash

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Booleans, what a wonderful type!
  2007-07-18  2:19 ` Al Viro
  2007-07-18  2:40   ` Brett Nash
@ 2007-07-18 16:33   ` Josh Triplett
  2007-07-19  0:23     ` ricknu-0
  1 sibling, 1 reply; 8+ messages in thread
From: Josh Triplett @ 2007-07-18 16:33 UTC (permalink / raw)
  To: Al Viro; +Cc: ricknu-0, linux-sparse

On Wed, 2007-07-18 at 03:19 +0100, Al Viro wrote:
> On Wed, Jul 18, 2007 at 03:43:39AM +0200, ricknu-0@student.ltu.se wrote:
> 
> > * Most likly a _really_ stupid newbie question, but I have seen several of this
> > form:
> > <function>
> > {
> >         <variable> a;
> >         <doing something useful (no sign of 'a')>
> >         a = <some value/variable>;
> >         <exit>
> > }
> > How is this variable useful?
> 
> Explain, please.  If you mean moving the declaration down - it's not
> idiomatic in C and frankly, C++ style tends to make declarations harder
> to find when you read the code.

Judging by that pseudocode, I would guess that he means the function
never uses the value of a after assigning to it.  That would generally
represent a bug.

- Josh Triplett

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Booleans, what a wonderful type!
  2007-07-18 16:33   ` Josh Triplett
@ 2007-07-19  0:23     ` ricknu-0
  0 siblings, 0 replies; 8+ messages in thread
From: ricknu-0 @ 2007-07-19  0:23 UTC (permalink / raw)
  To: Josh Triplett; +Cc: Al Viro, linux-sparse

Citerar Josh Triplett <josht@linux.vnet.ibm.com>:

> On Wed, 2007-07-18 at 03:19 +0100, Al Viro wrote:
> > On Wed, Jul 18, 2007 at 03:43:39AM +0200, ricknu-0@student.ltu.se wrote:
> > 
> > > * Most likly a _really_ stupid newbie question, but I have seen several
> of this
> > > form:
> > > <function>
> > > {
> > >         <variable> a;
> > >         <doing something useful (no sign of 'a')>
> > >         a = <some value/variable>;
> > >         <exit>
> > > }
> > > How is this variable useful?
> > 
> > Explain, please.  If you mean moving the declaration down - it's not
> > idiomatic in C and frankly, C++ style tends to make declarations harder
> > to find when you read the code.
> 
> Judging by that pseudocode, I would guess that he means the function
> never uses the value of a after assigning to it.  That would generally
> represent a bug.
> 
Yes exactly :)

Ok, then I know. Worrid it was some magic I could not get my mind around.

Thanks
Richard

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Booleans, what a wonderful type!
  2007-07-18  2:25 ` Al Viro
@ 2007-07-19  0:38   ` ricknu-0
  2007-07-19  7:30     ` Al Viro
  0 siblings, 1 reply; 8+ messages in thread
From: ricknu-0 @ 2007-07-19  0:38 UTC (permalink / raw)
  To: Al Viro; +Cc: linux-sparse

Citerar Al Viro <viro@ftp.linux.org.uk>:

> On Wed, Jul 18, 2007 at 03:43:39AM +0200, ricknu-0@student.ltu.se wrote:
> > Good morning to you all!
> > 
> > As most of you do not know, I am on Google's SoC
> >
> <http://code.google.com/soc/2007/sparse/appinfo.html?csaid=CB0974F67B64AD0C>
> to
> > add the ability to suggestions when booleans could/should be used.
> 
> Er...  Of _course_ booleans are values.  And yes, you can say true + false.
> Guaranteed to evaluate to int, value of expression being 1.  It's perfectly
> correct C99.  Same as true + true is guaranteed to be 2 (int, again);
> assigning
> that to _Bool variable is guaranteed to give 1, aka true (see the rules
> for conversion to _Bool).
Can you really say it really is a value? With C definition: ex an positiv
integer value => 'true' => value not zero, if converted from integer to boolean
and back. A value would return a specific value on the secound step, right?
> 
> Now, sparse handling of _Bool sucks in quite a few places (e.g. conversion
> to it is not reduction modulo 2, it's comparison with 0), but I wonder if
> that's what you have in mind...
My main goal is to make it able to find possible places where an integer is used
as an boolean.

Richard Knutsson

PS
Believe I used "Reply" instead of "Reply all" when I answeared your other mail.
So if you won't reply to any, could you please forward a copy to the list? Thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Booleans, what a wonderful type!
  2007-07-19  0:38   ` ricknu-0
@ 2007-07-19  7:30     ` Al Viro
  0 siblings, 0 replies; 8+ messages in thread
From: Al Viro @ 2007-07-19  7:30 UTC (permalink / raw)
  To: ricknu-0; +Cc: linux-sparse

On Thu, Jul 19, 2007 at 02:38:23AM +0200, ricknu-0@student.ltu.se wrote:
> > Er...  Of _course_ booleans are values.  And yes, you can say true + false.
> > Guaranteed to evaluate to int, value of expression being 1.  It's perfectly
> > correct C99.  Same as true + true is guaranteed to be 2 (int, again);
> > assigning
> > that to _Bool variable is guaranteed to give 1, aka true (see the rules
> > for conversion to _Bool).
> Can you really say it really is a value? With C definition: ex an positiv
> integer value => 'true' => value not zero, if converted from integer to boolean
> and back. A value would return a specific value on the secound step, right?

Yes.  RTFStandard, please.
 
> > Now, sparse handling of _Bool sucks in quite a few places (e.g. conversion
> > to it is not reduction modulo 2, it's comparison with 0), but I wonder if
> > that's what you have in mind...
> My main goal is to make it able to find possible places where an integer is used
> as an boolean.

I'm afraid that you are confused; what exactly do you mean by "boolean"?
Note that type of 1 == 1 is *not* _Bool; it's defined as int.  You can
convert it to _Bool, but that's it.

Please, read through the relevant sections of standard, starting with
6.3.1.2 and 6.3.1.1[2].  See also 6.5.3.4[5], 6.5.8, 6.5.9, 6.5.13 and
6.5.14 for operations resulting in int 0 or 1.  See 7.16 for stdbool
stuff.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-07-19  7:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-18  1:43 Booleans, what a wonderful type! ricknu-0
2007-07-18  2:19 ` Al Viro
2007-07-18  2:40   ` Brett Nash
2007-07-18 16:33   ` Josh Triplett
2007-07-19  0:23     ` ricknu-0
2007-07-18  2:25 ` Al Viro
2007-07-19  0:38   ` ricknu-0
2007-07-19  7:30     ` Al Viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).