Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!tut.cis.ohio-state.edu!uoft02.utoledo.edu!desire!demon From: demon@desire.wright.edu Newsgroups: comp.lang.c Subject: structure assignment, why you would want to do it Message-ID: <1096.26d52ea3@desire.wright.edu> Date: 24 Aug 90 18:41:55 GMT References: <1081.26d26274@desire.wright.edu> <352@saxony.pa.reuter.COM> <3615@goanna.cs.rmit.oz.au> Lines: 47 In article <3615@goanna.cs.rmit.oz.au>, ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes: > In article <352@saxony.pa.reuter.COM>, dgil@pa.reuter.COM (Dave Gillett) writes: > : In <1081.26d26274@desire.wright.edu> demon@desire.wright.edu writes: > : >struct_thing -= still_more_struct; > : >struct_thing *= even_more_struct; > : > : Recall that "x -= y" is equivalent to "x = x - y". Will your VAX C let > : you get away with "struct_thing = struct_thing - still_more_struct"? How > : have you declared "struct_thing" that lets it both (a) be a structure, and > : (b) be in the domain of subtraction, which normally works on *numbers*??? > > Let that stand as typical of the answers. > ..COBOL definitions/examples removed > and so on will do the trick. Given the equivalent of > struct { int a, b; float c; } x; > struct { int b, c, d; } y; > the COBOL equivalent of x += y would be > ADD CORRESPONDING y TO x. > which would do > /* x.a : no change, as there is no y.a field */ > x.b += y.b; > x.c += y.c; /* only the names have to match */ > /* y.d : not used, as there is no x.d field */ > > As it happens, this facility is not present in C. There is nothing in > the language which would make it especially difficult to implement, it's > just that nobody ever thought it worth while. It was a sensible question. > Thanx! Everyone wondered why I asked it. If you are doing transformations/similar math stuff or (like I'm doing) vehicle position updates for a military simulation, you'd like to be able to say pres_location += current_move; to update the vehicles location. I could go through and assign the x,y,z locations individually, but it would be nice (and cleaner looking) to do a structure assignment. It was intended that the assignement/operator would only be performed on like structure elements, and only on elements defined for the operater(s). Hmm, the next C standard is how many years away? :) Brett demon@wsu.bitnet