9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] quiz
@ 2007-06-06  0:36 ron minnich
  2007-06-06  0:43 ` Roman Shaposhnick
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: ron minnich @ 2007-06-06  0:36 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

/* catch the bug */

struct x {
  int botch:1;
};

fun(){
  struct x x;
  x.botch = 0;
  x.botch = 1;
}

ok, what's the bug? anyone? I just found this out today. (no, I don't
use bitfields, but insane people do)

ron


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

* Re: [9fans] quiz
  2007-06-06  0:36 [9fans] quiz ron minnich
@ 2007-06-06  0:43 ` Roman Shaposhnick
  2007-06-06  3:41   ` ron minnich
  2007-06-06  1:07 ` Paul Lalonde
  2007-06-06  8:49 ` [9fans] quiz prem
  2 siblings, 1 reply; 13+ messages in thread
From: Roman Shaposhnick @ 2007-06-06  0:43 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Tue, 2007-06-05 at 17:36 -0700, ron minnich wrote:
> /* catch the bug */
>
> struct x {
>   int botch:1;
> };
>
> fun(){
>   struct x x;
>   x.botch = 0;
>   x.botch = 1;
> }
>
> ok, what's the bug? anyone? I just found this out today. (no, I don't
> use bitfields, but insane people do)

  signed vs. unsigned int perhaps (meaning that x.botch becomes < 0
after the last assignment) ?

Thanks,
Roman.



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

* Re: [9fans] quiz
  2007-06-06  0:36 [9fans] quiz ron minnich
  2007-06-06  0:43 ` Roman Shaposhnick
@ 2007-06-06  1:07 ` Paul Lalonde
  2007-06-06  1:16   ` Roman Shaposhnick
  2007-06-06  8:49 ` [9fans] quiz prem
  2 siblings, 1 reply; 13+ messages in thread
From: Paul Lalonde @ 2007-06-06  1:07 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Signed bit field overflow.

You (don't) want "unsigned int botch:1;"

Yuck.

On 5-Jun-07, at 5:36 PM, ron minnich wrote:

> /* catch the bug */
>
> struct x {
>  int botch:1;
> };
>
> fun(){
>  struct x x;
>  x.botch = 0;
>  x.botch = 1;
> }
>
> ok, what's the bug? anyone? I just found this out today. (no, I don't
> use bitfields, but insane people do)
>
> ron

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)

iD8DBQFGZgi1pJeHo/Fbu1wRAk8AAJ9GjwNz6JLxWav33huG68SjB4R1YACfZHNI
BtIRBQPaXw91oj5Am+VDVaU=
=Ai0G
-----END PGP SIGNATURE-----


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

* Re: [9fans] quiz
  2007-06-06  1:07 ` Paul Lalonde
@ 2007-06-06  1:16   ` Roman Shaposhnick
  0 siblings, 0 replies; 13+ messages in thread
From: Roman Shaposhnick @ 2007-06-06  1:16 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Tue, 2007-06-05 at 18:07 -0700, Paul Lalonde wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Signed bit field overflow.
>
> You (don't) want "unsigned int botch:1;"
>
> Yuck.

  This bit of C is even more obscure. Consider this:

  struct {
    enum {A=-1} x:1;
  } s = {A};

  In this particular case you're at a total mercy of
  the compiler 'cause you can't really write '[un]signed enum'

Thanks,
Roman.



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

* Re: [9fans] quiz
  2007-06-06  0:43 ` Roman Shaposhnick
@ 2007-06-06  3:41   ` ron minnich
  2007-06-06  3:48     ` Roman Shaposhnik
  0 siblings, 1 reply; 13+ messages in thread
From: ron minnich @ 2007-06-06  3:41 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On 6/5/07, Roman Shaposhnick <rvs@sun.com> wrote:
> On Tue, 2007-06-05 at 17:36 -0700, ron minnich wrote:
> > /* catch the bug */
> >
> > struct x {
> >   int botch:1;
> > };
> >
> > fun(){
> >   struct x x;
> >   x.botch = 0;
> >   x.botch = 1;
> > }
> >
> > ok, what's the bug? anyone? I just found this out today. (no, I don't
> > use bitfields, but insane people do)
>
>   signed vs. unsigned int perhaps (meaning that x.botch becomes < 0
> after the last assignment) ?


yeah. x.botch is 0 after last assignment. Until recently, gcc would
give you dispensation and set x.botch to -1 anyway if you set x.botch
= 1. But, recently, it now figures out it's an overflow and sets
x.botch to 0. So, lots of code all over the place will now do the
unexpected, in reverse of what it used to do. It's interesting to
watch.

This change evidently broke much code. So folks are chasing down their
assignments all over the place, catching up with the change. Just saw
this going by the Xen list.

Bitfields are another story. People really love 'em in some parts of
this universe.

ron


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

* Re: [9fans] quiz
  2007-06-06  3:41   ` ron minnich
@ 2007-06-06  3:48     ` Roman Shaposhnik
  2007-06-06  4:18       ` ron minnich
  0 siblings, 1 reply; 13+ messages in thread
From: Roman Shaposhnik @ 2007-06-06  3:48 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Tue, 2007-06-05 at 20:41 -0700, ron minnich wrote:
> >   signed vs. unsigned int perhaps (meaning that x.botch becomes < 0
> > after the last assignment) ?
>
>
> yeah. x.botch is 0 after last assignment. Until recently, gcc would
> give you dispensation and set x.botch to -1 anyway if you set x.botch
> = 1. But, recently, it now figures out it's an overflow and sets
> x.botch to 0.

  Nice! That's an unexpected twist I must admit ;-) What version of
gcc does this?

Thanks,
Roman.



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

* Re: [9fans] quiz
  2007-06-06  3:48     ` Roman Shaposhnik
@ 2007-06-06  4:18       ` ron minnich
  2007-06-06  4:30         ` Kris Maglione
  0 siblings, 1 reply; 13+ messages in thread
From: ron minnich @ 2007-06-06  4:18 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On 6/5/07, Roman Shaposhnik <rvs@sun.com> wrote:

>   Nice! That's an unexpected twist I must admit ;-) What version of
> gcc does this?

I forget the exact version but it's the newer 4.x bits.

I wonder what kenc does :-)
Have not had a chance to try it.
Anyway, this whole note is more for amusement value than anything else.

ron


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

* Re: [9fans] quiz
  2007-06-06  4:18       ` ron minnich
@ 2007-06-06  4:30         ` Kris Maglione
  2007-06-06  4:36           ` Kris Maglione
  0 siblings, 1 reply; 13+ messages in thread
From: Kris Maglione @ 2007-06-06  4:30 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 417 bytes --]

On Tue, Jun 05, 2007 at 09:18:37PM -0700, ron minnich wrote:
> I wonder what kenc does :-)

i
#include <u.h>
#include <libc.h>

struct {
	int x:1;
} foo;

void
main(void) {
	foo.x = 1;
	print("foo.x: %d\n", foo.x);
	exits(0);
}
.
w
test.c: #134
!8c test.c && 8l test.8
!
!./8.out
foo.x: -1
!

-- 
Kris Maglione

The usefulness of any meeting
is in inverse proportion to the attendance.

[-- Attachment #2: Type: application/pgp-signature, Size: 194 bytes --]

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

* Re: [9fans] quiz
  2007-06-06  4:30         ` Kris Maglione
@ 2007-06-06  4:36           ` Kris Maglione
  2007-06-06  7:05             ` Bruce Ellis
  2007-06-06  8:15             ` W B Hacker
  0 siblings, 2 replies; 13+ messages in thread
From: Kris Maglione @ 2007-06-06  4:36 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 397 bytes --]

On Wed, Jun 06, 2007 at 12:30:55AM -0400, Kris Maglione wrote:
> !8c test.c && 8l test.8
> !
> !./8.out
> foo.x: -1
> !

Also:

!8c -wF test.c && 8l test.8
warning: test.c:11 format mismatch d LONG 0:1, arg 2
!

I'm surprised that there's not a warning about the overflow.

-- 
Kris Maglione

For every human problem, there is a neat, plain solution --
and it is always wrong.

[-- Attachment #2: Type: application/pgp-signature, Size: 194 bytes --]

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

* Re: [9fans] quiz
  2007-06-06  4:36           ` Kris Maglione
@ 2007-06-06  7:05             ` Bruce Ellis
  2007-06-06  8:15             ` W B Hacker
  1 sibling, 0 replies; 13+ messages in thread
From: Bruce Ellis @ 2007-06-06  7:05 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

easy.  ken had (has) no respect for bitfields.
he is a wise man.

brucee

On 6/6/07, Kris Maglione <bsdaemon@comcast.net> wrote:
> On Wed, Jun 06, 2007 at 12:30:55AM -0400, Kris Maglione wrote:
> > !8c test.c && 8l test.8
> > !
> > !./8.out
> > foo.x: -1
> > !
>
> Also:
>
> !8c -wF test.c && 8l test.8
> warning: test.c:11 format mismatch d LONG 0:1, arg 2
> !
>
> I'm surprised that there's not a warning about the overflow.
>
> --
> Kris Maglione
>
> For every human problem, there is a neat, plain solution --
> and it is always wrong.
>
>


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

* Re: [9fans] quiz
  2007-06-06  4:36           ` Kris Maglione
  2007-06-06  7:05             ` Bruce Ellis
@ 2007-06-06  8:15             ` W B Hacker
  1 sibling, 0 replies; 13+ messages in thread
From: W B Hacker @ 2007-06-06  8:15 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Kris Maglione wrote:
> On Wed, Jun 06, 2007 at 12:30:55AM -0400, Kris Maglione wrote:
>> !8c test.c && 8l test.8
>> !
>> !./8.out
>> foo.x: -1
>> !
>
> Also:
>
> !8c -wF test.c && 8l test.8
> warning: test.c:11 format mismatch d LONG 0:1, arg 2
> !
>
> I'm surprised that there's not a warning about the overflow.
>

C *requires* the ability to create overflow situations w/o warning either by
accident, design, or randomly. Job security bureau dictate AFAIK.

What other 'feature' has been so steadfastly preserved?

Just wouldn't be 'C' without overflows...

Bill


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

* [9fans] Re: quiz
  2007-06-06  0:36 [9fans] quiz ron minnich
  2007-06-06  0:43 ` Roman Shaposhnick
  2007-06-06  1:07 ` Paul Lalonde
@ 2007-06-06  8:49 ` prem
  2 siblings, 0 replies; 13+ messages in thread
From: prem @ 2007-06-06  8:49 UTC (permalink / raw)
  To: 9fans

http://publications.gbdirect.co.uk/c_book/chapter6/bitfields.html
I found this very interestnig... and discuss the signed ness in a bit
field


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

* [9fans] quiz
@ 2002-05-02  5:55 rob pike, esq.
  0 siblings, 0 replies; 13+ messages in thread
From: rob pike, esq. @ 2002-05-02  5:55 UTC (permalink / raw)
  To: 9fans

An entertainment for new users.  Find the purpose and implementation of
the following two commands, revered in 9dom for their funny names with
surprising pronunciations:

	wormingest (easy)
	dopermind (harder)

Plese don't send your answers to 9fans and ruin the fun for others.

-rob



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

end of thread, other threads:[~2007-06-06  8:49 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-06  0:36 [9fans] quiz ron minnich
2007-06-06  0:43 ` Roman Shaposhnick
2007-06-06  3:41   ` ron minnich
2007-06-06  3:48     ` Roman Shaposhnik
2007-06-06  4:18       ` ron minnich
2007-06-06  4:30         ` Kris Maglione
2007-06-06  4:36           ` Kris Maglione
2007-06-06  7:05             ` Bruce Ellis
2007-06-06  8:15             ` W B Hacker
2007-06-06  1:07 ` Paul Lalonde
2007-06-06  1:16   ` Roman Shaposhnick
2007-06-06  8:49 ` [9fans] quiz prem
  -- strict thread matches above, loose matches on Subject: below --
2002-05-02  5:55 [9fans] quiz rob pike, esq.

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).