Path: utzoo!utgpu!watserv1!watmath!att!westmark!mole-end!mat From: mat@mole-end.UUCP (Mark A Terribile) Newsgroups: comp.lang.c Subject: Re: structure assignment, why you would want to do it Summary: On beyond C, bro'! Message-ID: <429@mole-end.UUCP> Date: 30 Aug 90 07:19:04 GMT References: <1081.26d26274@desire.wright.edu> <352@saxony.pa.reuter.COM> <1096.26d52ea3@desire.wright.edu> Organization: mole-end--private system. admin: mole-end!newtnews Lines: 55 >> : 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*??? In other words, you want to define operations + and - on struct types or your own design. > > 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. Weelll ... what happens when you have stored in that struct not only coordinates but also data that are not to be added, subtracted, &c? Like, for instance, a name string? There's more to be done than the compiler can do automatically. > 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). Well, OK, but what if your coordinates are polar? Or direction cosines? Or ... ? I still think that you need a way to tell the compiler what the operators mean when applied to these structs of yours. > Hmm, the next C standard is how many years away? :) C is probably the wrong place to look for this stuff. Expect new C standards to be clarifications and tweaks and numerical stuff, and maybe conformant array parameters. The place to look (as if everyone hadn't by now guessed it) is C++, which allows you to program just exactly what you have asked for here. Yes, really, even including the + and - operators. And it's not years away, it's here NOW. Don't expect to get things for free; the step from C to C++ is not a simple one. If I have you in a classroom, we will spend 50 hours doing it, and you will spend at least 100 hours on assignments to master the core of the language. What your asking for isn't simple. You can get it, but there is a price to be paid. -- (This man's opinions are his own.) From mole-end Mark Terribile