home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.sys.sgi:19063 comp.sys.sgi.apps:101
- Path: sparky!uunet!olivea!sgigate!odin!sgihub!zola!arthur
- From: arthur@sgi.com (Arthur Evans)
- Newsgroups: comp.sys.sgi,comp.sys.sgi.apps
- Subject: Re: help with IPC
- Message-ID: <v7egfpc@zola.esd.sgi.com>
- Date: 23 Jan 93 02:29:51 GMT
- References: <1993Jan14.002814.11411@eos.arc.nasa.gov> <uslbhsg@zola.esd.sgi.com> <1jkqu9INNqf8@news.cerf.net>
- Sender: news@zola.esd.sgi.com (Net News)
- Reply-To: arthur@chiba.esd.sgi.com (Arthur Evans)
- Organization: Silicon Graphics, Inc.
- Lines: 60
-
-
- In article <1jkqu9INNqf8@news.cerf.net> pete@ent-img.com writes:
- >In article <uslbhsg@zola.esd.sgi.com> arthur@chiba.esd.sgi.com (Arthur Evans) writes:
- >>This works because msgbuf and msgbuf1 are essentially
- >>the same structure. Both consist of a long and a char
- >>pointer (that is, an array of char).
- >NO NO NO - This is a common misconception which K&R unwittingly
- >lead people into, since you can pass an array name as if it were
- >a pointer to char, but a char pointer and an array of char are NOT
- >the same thing at all.
-
- You're right, of course. I knew there was some
- reason that the example code in question would work
- (at least before ANSI) but I clearly wasn't thinking
- too hard when I tried to explain it.
-
- >You aren't alone with this misconception - K&R's explanation leaves
- >a lot to your imagination (or prior knowledge).
- >The name of an array of char has the syntactic type of "pointer to char"
- >in most contexts (but not the same semantics at all - try sizeof() on
- >both and see what you get)... This particular struct really does use the
- >"array of char" meaning.
- >
- >>Now, it's a mystery to me why mtext is declared as
- >>char mtext[1] in the header file, as opposed to
- >>char *mtext, but I suppose there's some good reason
- >>for it (like everything else in UNIX ;-).
- >This is because the array is itself IN THE STRUCTURE, not in remote
- >memory pointed to from the structure.
- [ ... ]
-
- Alright, now I feel stupid. Someone explained this to
- me once, and I had the vauge unsettling feeling while
- I was posting the article that I should *know* why
- mtext was declared that way.
-
- In light of this, a better answer to the original question
- would be that the example program should be rewritten
- such that it dynamically allocates space for the msgbuf
- structures, with the appropriate amount of added space
- for the message text.
-
- >>By the way, if you have any other comments about the
- >>IRIX Programming Guide, please forward them to me,
- >>arthur@esd.sgi.com--I'm in charge of revising this
- >>book for IRIX 5.0. [ ... ] Any thoughts on what
- >>could use more or less coverage in a new version of this
- >>book would also be welcome.
- >Well, please talk to a programmer who understands the reasons
- >behind some of these kluges (yes, they are kluges) before writing
- >it up.
-
- I assure you that the manual will receive both more thought
- and more review that my average netnews posting ;-).
-
- Anyway, thanks for keeping me honest.
-
- >-- Pete
-
- -arthur
-