Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!ncar!noao!arizona!dave From: dave@cs.arizona.edu (Dave P. Schaumann) Newsgroups: comp.lang.c Subject: Re: Question: Representing complex numbers in C Message-ID: <974@caslon.cs.arizona.edu> Date: 28 Feb 91 03:32:14 GMT References: <12620.27cbe36f@ecs.umass.edu> Organization: U of Arizona CS Dept, Tucson Lines: 28 In article <12620.27cbe36f@ecs.umass.edu> lim@ecs.umass.edu writes: >[FORTRAN can do this:] > >COMPLEX x, y, z; >z = x + y; >etc. > >[How is it done in C?] Can't be done. The closest you can come is typedef struct { double r ; doube i } complex ; complex x, y, z ; ... z.r = x.r + y.r ; z.i = x.i + y.i ; Now, you could make it a little better by defining functions to do addition, and other ops, but that's as close as you can get in C. C++ on the other hand, will let you overload the + operator with new operations, just as you want. -- Dave Schaumann dave@cs.arizona.edu 'Dog Gang'! Where do they get off calling us the 'Dog Gang'? I'm beginning to think the party's over. I'm beginning to think maybe we don't need a dog. Or maybe we need a *new* dog. Or maybe we need a *cat*! - Amazing Stories