Path: utzoo!attcan!uunet!mcsun!unido!ztivax!sinix!pete From: pete@sinix.UUCP (Pete Delany) Newsgroups: comp.lang.c Subject: Re: Re: What should "*nft = *(struct need_to_free *) ntf->addr;" do? Summary: Structure assignment similar to bcopy()? Keywords: structure assignment atomic Message-ID: <1527@athen.sinix.UUCP> Date: 5 Sep 90 11:47:02 GMT Expires: 5 Sep 90 11:46:52 GMT Reply-To: pete@athen.sp4n1.siemens.de (Pete Delany), john@athen.sp4n1.siemens.de (John Wood), ritchie@att.com (Dennis Ritchie) Followup-To: comp.lang.c Distribution: comp.lang.c Organization: Siemens AG, DI ST SP4, Munich Lines: 124 In article <12939@hydra.gatech.EDU> cc100aa@prism.gatech.EDU (Ray Spalding) writes: >It seems to me that the code is just fine, except: >(1) As was pointed out in another thread today, there's no guarantee >that "kmem_info.need_to_free_list" is represented the same as "struct >need_to_free" unless it is defined AS a "struct need_to_free". Great thats one vote for the compiler having a BUG, thanks. But we need lots more votes; keep thoses votes comming in. Your right kmem_info.need_to_free_list should have been declared in the example, it is in ../sys/heap_kmem.c. >That is, distinct structs defined with similar source code may not in fact >have the same layout in memory. But, one can probably get away with it >in this case most times. What? I thought all structures for the save archecture have the same layout. At least for the same system. Right? >(2) The cast (struct need_to_free *) seems redundant-- isn't that the >declared type of ntf->addr? Couldn't that line just read >"*ntf = *ntf->addr;"? Your right, in trying to simplify the example I missed that. I should have made it: struct need_to_free { struct need_to_free *addr; int nbytes; }; struct kmem_info { int misc_stuff; struct neet_to_free need_to_free_list; } check_need_to_free() { struct need_to_free *ntf = &kmem_info.need_to_free_list; again: ntf = &kmem_info.need_to_free_list; if(ntf->addr) { int addr = *ntf->addr; int nbytes = *ntf->addr; *ntf = *ntf->addr; /* BUG or FEATURE */ kmem_free(addr, nbytes); goto again; } } ======== Unfortuneately I currently have to hack the kernel with something like: ======== #define COMPILER_STRUCTURE_ASSIGNMENT_BUG struct need_to_free { struct need_to_free *addr; int nbytes; }; struct kmem_info { int misc_stuff; struct neet_to_free need_to_free_list; } check_need_to_free() { struct need_to_free *ntf = &kmem_info.need_to_free_list; again: ntf = &kmem_info.need_to_free_list; if(ntf->addr) { int addr = *ntf->addr; int nbytes = *ntf->addr; #ifdef COMPILER_STRUCTURE_ASSIGNMENT_BUG tmp_ntf = *ntf->addr; *ntf = tmp_ntf; #else *ntf = *ntf->addr; /* BUG or FEATURE */ #endif kmem_free(addr, nbytes); goto again; } } ======== I wonder why no one else has an opinion on the efficiecy of this code. Clearly we think the the structure pointed to by ntf->addr will be copied to kmem_info.need_to_free_list. Unfortunately it's not clear yet that all us non-authoritians see it that way, or, that the great wizzards and central committee types give it their blessing. > >Your reference to the standard seems irrelevant here. The value being >stored does not overlap the object being stored into at all-- the two >objects are in two different, non-overlapping areas of memory (unless >the pointers have been corrupted). Perhaps the greatest reason that I presented the ANSI C paragraph is that my friend, who accepted my DM100 bet, presented it to me as the defense to his position; insisting that the structures did overlap. So I have tried to see the efficiacy of his position. But as you can see from my posting, that upon rearranging the text from committee language to english to simple logic that it doesn't seem to defend his position. Clearly Ray agrees with me and the authors of the heap_kmem.c code. Unfortunately, just your opinion likely wont get our corporative digestive track accepting this 'feature' as a BUG without either *lots* of opinions (come on guys how about a tiny posting) or words-of-wisdom from the authorities or powers that be. I also expect that a single 'yea' is not sufficient to win my DM 100 so I can buy some cheap silver; Hmmm I wonder if Rosenthal is right about sivler going to $4 and then to $10 or higher. Lets see DM100 => about a pound of sterling silver dollars; ... Where are Dennis Ritchie and the ANSI C party types when you need them? :-) -pete