From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Tue, 7 Oct 2014 17:24:52 +0200 From: Carsten Kunze To: 9fans@9fans.net Message-ID: <1341360045.898340.1412695492957.JavaMail.ngmail@webmail12.arcor-online.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: [9fans] C question on struct Biobuf in bio.h Topicbox-Message-UUID: 18cedc8c-ead9-11e9-9d60-3106f5b1d025 Hello, in bio.h there is a struct Biobuf { Biobufhdr; uchar b[Bungetsize+Bsize]; }; where Biobufhdr is declared as typedef struct Biobufhdr Biobufhdr; To make it compile with gcc under UNIX I changed the struct to struct Biobuf { Biobufhdr Biobufhdr; uchar b[Bungetsize+Bsize]; }; but is that what is meant by the original description above? Carsten From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: <1341360045.898340.1412695492957.JavaMail.ngmail@webmail12.arcor-online.net> References: <1341360045.898340.1412695492957.JavaMail.ngmail@webmail12.arcor-online.net> Date: Tue, 7 Oct 2014 17:35:00 +0200 Message-ID: From: =?UTF-8?B?QmVuY2UgRsOhYmnDoW4=?= To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: multipart/alternative; boundary=089e013a214e3a150d0504d6f152 Subject: Re: [9fans] C question on struct Biobuf in bio.h Topicbox-Message-UUID: 18f4f340-ead9-11e9-9d60-3106f5b1d025 --089e013a214e3a150d0504d6f152 Content-Type: text/plain; charset=UTF-8 hi, no, it is an anonym field. and it is used in a way that is not part of ansi c. there is an extension in newer versions of gcc which supports it, but if you wan't to port plan 9 c to unix you can use the libs from plan9port. that's far more easier. bence 2014-10-07 17:24 GMT+02:00 Carsten Kunze : > Hello, > > in bio.h there is a > > struct Biobuf > { > Biobufhdr; > uchar b[Bungetsize+Bsize]; > }; > > where Biobufhdr is declared as > > typedef struct Biobufhdr Biobufhdr; > > To make it compile with gcc under UNIX I changed the struct to > > struct Biobuf > { > Biobufhdr Biobufhdr; > uchar b[Bungetsize+Bsize]; > }; > > but is that what is meant by the original description above? > > Carsten > > --089e013a214e3a150d0504d6f152 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
hi,

no, it is an anonym field.=C2= =A0 and it is used in a way that is not part
of ansi c.=C2=A0 there is a= n extension in newer versions of gcc which
supports it, but if you wan&#= 39;t to port plan 9 c to unix you can use the
libs from plan9port.=C2=A0= that's far more easier.

bence

2014-10-07 17:24 GMT+02:00 Carsten = Kunze <carsten.kunze@arcor.de>:
Hello,

in bio.h there is a

struct=C2=A0 Biobuf
{
=C2=A0 =C2=A0 =C2=A0 =C2=A0 Biobufhdr;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 uchar=C2=A0 =C2=A0b[Bungetsize+Bsize];
};

where Biobufhdr is declared as

typedef struct=C2=A0 Biobufhdr=C2=A0 =C2=A0 =C2=A0 =C2=A0Biobufhdr;

To make it compile with gcc under UNIX I changed the struct to

struct=C2=A0 Biobuf
{
=C2=A0 =C2=A0 =C2=A0 =C2=A0 Biobufhdr Biobufhdr;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 uchar=C2=A0 =C2=A0b[Bungetsize+Bsize];
};

but is that what is meant by the original description above?

=C2=A0 =C2=A0Carsten


--089e013a214e3a150d0504d6f152-- From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: <1341360045.898340.1412695492957.JavaMail.ngmail@webmail12.arcor-online.net> References: <1341360045.898340.1412695492957.JavaMail.ngmail@webmail12.arcor-online.net> Date: Tue, 7 Oct 2014 17:41:38 +0200 Message-ID: From: David du Colombier <0intro@gmail.com> To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: text/plain; charset=UTF-8 Subject: Re: [9fans] C question on struct Biobuf in bio.h Topicbox-Message-UUID: 18fb422c-ead9-11e9-9d60-3106f5b1d025 > in bio.h there is a > > struct Biobuf > { > Biobufhdr; > uchar b[Bungetsize+Bsize]; > }; > > where Biobufhdr is declared as > > typedef struct Biobufhdr Biobufhdr; This is an unnamed structure. Recent versions of GCC should be able to handle them when setting the -fplan9-extension flag. Otherwise, your change is fine, but "hdr" would probably be a better name than "Biobufhdr". Also, don't forget to update your code to use b->hdr.fid instead of b->fid, and so on. -- David du Colombier From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Tue, 7 Oct 2014 17:58:36 +0200 From: Carsten Kunze To: 9fans@9fans.net Message-ID: <1959055281.1911186.1412697516384.JavaMail.ngmail@webmail14.arcor-online.net> In-Reply-To: References: <1341360045.898340.1412695492957.JavaMail.ngmail@webmail12.arcor-online.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [9fans] C question on struct Biobuf in bio.h Topicbox-Message-UUID: 18ffcce8-ead9-11e9-9d60-3106f5b1d025 > Otherwise, your change is fine, but "hdr" would probably be > a better name than "Biobufhdr". Also, don't forget to update > your code to use b->hdr.fid instead of b->fid, and so on. Thanks for all answers! (They also helped to find a short documentation in /sys/doc/compiler) Carsten From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: <1959055281.1911186.1412697516384.JavaMail.ngmail@webmail14.arcor-online.net> References: <1341360045.898340.1412695492957.JavaMail.ngmail@webmail12.arcor-online.net> <1959055281.1911186.1412697516384.JavaMail.ngmail@webmail14.arcor-online.net> From: =?UTF-8?Q?=C3=81lvaro_Jurado?= Date: Tue, 7 Oct 2014 19:27:42 +0200 Message-ID: To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: multipart/alternative; boundary=f46d04388e697969410504d88542 Subject: Re: [9fans] C question on struct Biobuf in bio.h Topicbox-Message-UUID: 19113320-ead9-11e9-9d60-3106f5b1d025 --f46d04388e697969410504d88542 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I'm using gcc to compile plan9 code from some time (4.7/4.8) and that option are masking real behaviour. Do not warns or put out an error about "anonymous structs", but you will have a conflict if to structs in the same source are including a, for example, "Lock;" element, and ld could not assign right the values if declarations are not specified ansi style (variable initialization it's made by ld, not by the compiler): you will get some dragons in some cases. Look at LP49 source code and you will see that authors used your second way= . =C3=81lvaro Jurado Cuevas colmenar.biz.tm 2014-10-07 17:58 GMT+02:00 Carsten Kunze : > > Otherwise, your change is fine, but "hdr" would probably be > > a better name than "Biobufhdr". Also, don't forget to update > > your code to use b->hdr.fid instead of b->fid, and so on. > > Thanks for all answers! > > (They also helped to find a short documentation in /sys/doc/compiler) > > Carsten > > --f46d04388e697969410504d88542 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I'm using gcc to compile plan9 code from some time (4.= 7/4.8) and that option are masking real behaviour. Do not warns or put out = an error about "anonymous structs", but you will have a conflict = if to structs in the same source are including a, for example, "Lock;&= quot; element, and ld could not assign right the values if declarations are= not specified ansi style (variable initialization it's made by ld, not= by the compiler): you will get some dragons in some cases.
Look at LP4= 9 source code and you will see that authors used your second way.

=C3=81= lvaro Jurado Cuevas

2014-10-07 17:58 GMT+02:00 Carsten Kunze <carsten.kunze@arcor.de>:
> Otherwise, your change is fine, but "hdr"= would probably be
> a better name than "Biobufhdr". Also, don't forget to up= date
> your code to use b->hdr.fid instead of b->fid, and so on.

Thanks for all answers!

(They also helped to find a short documentation in /sys/doc/compiler)

=C2=A0 =C2=A0Carsten


--f46d04388e697969410504d88542-- From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: References: <1341360045.898340.1412695492957.JavaMail.ngmail@webmail12.arcor-online.net> <1959055281.1911186.1412697516384.JavaMail.ngmail@webmail14.arcor-online.net> Date: Wed, 8 Oct 2014 14:35:21 +0100 Message-ID: From: Charles Forsyth To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: multipart/alternative; boundary=f46d04447fe52e0cb20504e96368 Subject: Re: [9fans] C question on struct Biobuf in bio.h Topicbox-Message-UUID: 192d6478-ead9-11e9-9d60-3106f5b1d025 --f46d04447fe52e0cb20504e96368 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 7 October 2014 18:27, =C3=81lvaro Jurado wrote: > > , and ld could not assign right the values if declarations are not > specified ansi style (variable initialization it's made by ld, not by the > compiler): you will get some dragons in some cases. Initialisations of externals is done by the compiler, which lays things out as .long etc. ld doesn't do anything special; it doesn't even know about them. --f46d04447fe52e0cb20504e96368 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

= On 7 October 2014 18:27, =C3=81lvaro Jurado <elbingmiss@gmail.com= > wrote:

, and ld could not assign right the values if dec= larations are not specified ansi style (variable initialization it's ma= de by ld, not by the compiler): you will get some dragons in some cases.

Initialisations of externals is done by the c= ompiler, which lays things out as .long etc. ld doesn't do anything spe= cial; it doesn't even know about them.


--f46d04447fe52e0cb20504e96368--