9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] C question on struct Biobuf in bio.h
@ 2014-10-07 15:24 Carsten Kunze
  2014-10-07 15:35 ` Bence Fábián
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Carsten Kunze @ 2014-10-07 15:24 UTC (permalink / raw)
  To: 9fans

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



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

* Re: [9fans] C question on struct Biobuf in bio.h
  2014-10-07 15:24 [9fans] C question on struct Biobuf in bio.h Carsten Kunze
@ 2014-10-07 15:35 ` Bence Fábián
  2014-10-07 15:41 ` David du Colombier
  2014-10-07 15:58 ` Carsten Kunze
  2 siblings, 0 replies; 6+ messages in thread
From: Bence Fábián @ 2014-10-07 15:35 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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

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 <carsten.kunze@arcor.de>:

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

[-- Attachment #2: Type: text/html, Size: 1310 bytes --]

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

* Re: [9fans] C question on struct Biobuf in bio.h
  2014-10-07 15:24 [9fans] C question on struct Biobuf in bio.h Carsten Kunze
  2014-10-07 15:35 ` Bence Fábián
@ 2014-10-07 15:41 ` David du Colombier
  2014-10-07 15:58 ` Carsten Kunze
  2 siblings, 0 replies; 6+ messages in thread
From: David du Colombier @ 2014-10-07 15:41 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> 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



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

* Re: [9fans] C question on struct Biobuf in bio.h
  2014-10-07 15:24 [9fans] C question on struct Biobuf in bio.h Carsten Kunze
  2014-10-07 15:35 ` Bence Fábián
  2014-10-07 15:41 ` David du Colombier
@ 2014-10-07 15:58 ` Carsten Kunze
  2014-10-07 17:27   ` Álvaro Jurado
  2 siblings, 1 reply; 6+ messages in thread
From: Carsten Kunze @ 2014-10-07 15:58 UTC (permalink / raw)
  To: 9fans

> 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



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

* Re: [9fans] C question on struct Biobuf in bio.h
  2014-10-07 15:58 ` Carsten Kunze
@ 2014-10-07 17:27   ` Álvaro Jurado
  2014-10-08 13:35     ` Charles Forsyth
  0 siblings, 1 reply; 6+ messages in thread
From: Álvaro Jurado @ 2014-10-07 17:27 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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

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.

Álvaro Jurado Cuevas
colmenar.biz.tm

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

[-- Attachment #2: Type: text/html, Size: 1564 bytes --]

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

* Re: [9fans] C question on struct Biobuf in bio.h
  2014-10-07 17:27   ` Álvaro Jurado
@ 2014-10-08 13:35     ` Charles Forsyth
  0 siblings, 0 replies; 6+ messages in thread
From: Charles Forsyth @ 2014-10-08 13:35 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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

On 7 October 2014 18:27, Álvaro Jurado <elbingmiss@gmail.com> 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.

[-- Attachment #2: Type: text/html, Size: 886 bytes --]

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

end of thread, other threads:[~2014-10-08 13:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-07 15:24 [9fans] C question on struct Biobuf in bio.h Carsten Kunze
2014-10-07 15:35 ` Bence Fábián
2014-10-07 15:41 ` David du Colombier
2014-10-07 15:58 ` Carsten Kunze
2014-10-07 17:27   ` Álvaro Jurado
2014-10-08 13:35     ` Charles Forsyth

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