Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!decwrl!pyramid!pesnta!amd!vecpyr!lll-lcc!lll-crg!seismo!rochester!ritcv!ccivax!rb From: rb@ccivax.UUCP (rex ballard) Newsgroups: net.lang.c Subject: Re: Need help with C (struct comparison) Message-ID: <379@ccivax.UUCP> Date: Fri, 7-Feb-86 18:17:44 EST Article-I.D.: ccivax.379 Posted: Fri Feb 7 18:17:44 1986 Date-Received: Tue, 11-Feb-86 04:37:58 EST References: <124@dg_rtp.UUCP> Reply-To: rb@ccivax.UUCP (What's in a name ?) Organization: CCI Telephony Systems Group, Rochester NY Lines: 55 In article <124@dg_rtp.UUCP> throopw@dg_rtp.UUCP writes: > struct datestruct date; > struct dbstruct dbase[63]; > > I try to do a comparison between these, i.e. > > ( date == dbase[loop].date ) > > but the compiler blows up on this, saying the two are incompatible. The basic problem is that the 'C' doesn't do composite comparisons. Suppose you declared datestruct as struct datestruct { int yy; /* year */ int mm; /* month */ int dd; /* day */ } On a 68000 machine you could use bcmp(); But on a VAX, 808X, or PDP-11, byte ordering of words is not Most Significant to Least Significant, therefore the code would be non-portable. What you need here is a function to compare two dates; Of course you need functions to compare other complex types as well. You could use an object oriented language such as C++ which would be able to interpret this as a function call to a complex structure type. Some C compilers are able to do assignment automatically by using bcopy, because the order will be preserved automatically. However, this is a relatively new feature, and is not really portable unless you use an actual call to bcopy(). The same is true with passing structures and arrays (rather than just pointers) to functions. What an object oriented language (C++ or Objective C) does for you is to intercept the '==' and the two types and call the appropriate structure comparison routine (which may be automatically generated in some languages). This is one of the reasons the 'sort()' routine has such an unusual calling sequence. Of course, one advantage of C is that you don't automatically get compare routines for every composite structure you want to use. If you can, go back a few articles in this group and read some of the comments on these 'Object Oriented' versions of the language. Perhaps a variation of C++ will become a standard superset of the standard language. It would be nice to have addition, subtraction, assignment, concatenation, 'to ascii', print, input, and file I/O of complex types. How about a capability for specifying which of these operations you actually plan to use (something many OOL's lack) either at declaration time or by the linker? Or am I the only one who has ever had to write stubs for the 'printf/scanf floating point' to make an application fit the constraints of the machine?