The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: Bakul Shah <bakul@bitblocks.com>
To: "<ron@ronnatalie.com>" <ron@ronnatalie.com>
Cc: TUHS <tuhs@minnie.tuhs.org>
Subject: Re: [TUHS] C++ / Kernel
Date: Thu, 23 Aug 2018 18:41:19 -0700	[thread overview]
Message-ID: <4130AFB4-1740-46BC-AA98-F9D01549049C@bitblocks.com> (raw)
In-Reply-To: <151301d43b2f$07881ed0$16985c70$@ronnatalie.com>



> On Aug 23, 2018, at 3:17 PM, <ron@ronnatalie.com> <ron@ronnatalie.com> wrote:
> 
> 
> 
>> I haven't done much BSD kernel programming in last 15 years but this is
> not my recollection. BSD used caddr_t, typedefed to char*, sort of as void
> *. IIRC void* 
>> came in common use after BSD unix first came about. Why use a union when a
> cast will do? :-) The union trick is more likely to be used for esoteric
> things 
>> (like getting at fl.pt. bytes) or for more complex types or probably by
> people with lots of programming experience in pascal and not so much in C
> (in Pascal 
>> you *had* to use untagged variant records if you wanted to cheat!). In C,
> all that void* does is allow you to avoid casts in some cases.
> 
> Your recollections are certainly wrong.    I spent a lot of time tracing
> down why the Kernel crashed doing I/O and traced it to this and spent a
> while undoing it as I stated.
> This union was right in the middle of the buf struct:
> 
> 	union {
> 	    caddr_t b_addr;		/* low order core address */
> 	    int	*b_words;		/* words for clearing */
> 	    struct filsys *b_filsys;	/* superblocks */
> 	    struct dinode *b_dino;	/* ilist */
> 	    daddr_t *b_daddr;		/* indirect block */
> 	} b_un;
> There were a number of other places that did the same thing.   It's
> OFFICIALLY now in undefined behavior by the standard (though of course that
> didn't exist in the BSD days) ,
> to store in one element of the union and retrieve it via another.   This is
> one of the reasons why.

Note that this is a legitimate use of union. That is,
unless I misunderstood what you meant by it, there is
no "conversion by union" as you call it or "cheating"
as I call it or type punning. There is no put one thing
in and take another thing out. Now it may be that
someone misused such a union. This is easy to do as,
unlike Pascal, C has no tagged variant record & it is
user's responsibility to use it right.

> 
> This isn't the only place it occurs.
> 
> Void* came out with the V7 compiler, if I recall properly.   The BSD kernel
> looks as if it requires such a later compiler (it uses bit fields which the
> earlier compilers didn't support).

From what I recall {c,m,re}alloc() returned a char*, not a void *.
I don't have K&R1 handy at the moment so can't recall if void* was
mentioned in the book (if not, that could be one reason for a lack of
its use).

  parent reply	other threads:[~2018-08-24  1:41 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-23 14:42 ron
2018-08-23 17:24 ` Clem Cole
2018-08-23 20:21 ` Bakul Shah
2018-08-23 22:17   ` ron
2018-08-23 22:28     ` Nevin Liber
2018-08-23 22:48       ` Clem Cole
2018-08-23 23:14     ` Steffen Nurpmeso
2018-08-24 14:13       ` Steffen Nurpmeso
2018-08-24 14:32         ` ron
2018-08-24 18:15           ` Steffen Nurpmeso
2018-08-26 16:34             ` Paul Winalski
2018-08-27 16:31               ` Steffen Nurpmeso
2018-08-24  1:41     ` Bakul Shah [this message]
2018-08-24 10:41       ` Pete Turnbull
2018-08-24 12:17       ` ron
2018-08-24 18:36         ` Bakul Shah
2018-08-24 18:38           ` ron
2018-08-24  1:58     ` Dan Cross
2018-08-24  3:04       ` Clem cole
2018-08-24 14:01         ` Dan Cross
2018-08-24 13:22 ` Derek Fawcus
2018-08-24 16:59   ` Steffen Nurpmeso
2018-08-23 23:29 Noel Chiappa
2018-08-23 23:42 ` ron
2018-08-24  0:30   ` Clem Cole
2018-08-24  2:05     ` Bakul Shah
2018-08-24 12:21     ` ron
2018-08-24  1:27 Noel Chiappa
2018-08-24  2:52 ` Clem cole
2018-08-24  7:30 Paul Ruizendaal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4130AFB4-1740-46BC-AA98-F9D01549049C@bitblocks.com \
    --to=bakul@bitblocks.com \
    --cc=ron@ronnatalie.com \
    --cc=tuhs@minnie.tuhs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).