Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!rochester!PT!ius1.cs.cmu.edu!edw From: edw@ius1.cs.cmu.edu (Eddie Wyatt) Newsgroups: comp.lang.c Subject: Re: *\"LDA\" ok? Message-ID: <1039@ius1.cs.cmu.edu> Date: Thu, 27-Aug-87 18:23:34 EDT Article-I.D.: ius1.1039 Posted: Thu Aug 27 18:23:34 1987 Date-Received: Sun, 30-Aug-87 02:06:04 EDT References: <8877@brl-adm.ARPA> <8088@mimsy.UUCP> <87@splut.UUCP> <2211@emory.uucp> Organization: Carnegie-Mellon University, CS/RI Lines: 82 In article <2211@emory.uucp>, arnold@emory.uucp (Arnold D. Robbins {EUCC}) writes: > There has been considerable discussion about C's strings and the fact that > the lack of string operands is a hindrance. Several years ago I suggested > a string operator, but I got little response. Here's my idea again. > > Add a new symbol for use in comparison, assignment, and argument declarations > and functions calls that pass arrays *by value*, say "`". It would be > used analogously to * in pointer declarations/use. > > Array comparison: > if (`x == `y) > if (`x == `"LDA") > > Function declaration: > int foo (char `arg); /* requires dope vector */ > x = foo (`x); > char (`junk[5])(); /* function returning array! (length 5) */ > > Array assignment: > `x = `y; The problem with applying these operations to arrays in general is that the size of an array may be (is usually) unknown to the compiler. x = (int *) malloc(sizeof(int)*4000); `y = `x; How many bytes should be copied???? Can't know unless the compiler understands the sematics of the first statement. I'm sure you can start to imagine all the posible bad situations. You may restrict the ` operator to arrays with known bounds (ie an array declaration for the variables involved is within scope - int x[3], y[3], not int *x, y[3]) But if this restrict is made then the facility becomes of very little use for a lot of code assumes unbounded array and hence could not take advantage of this construct. > > There would have to be a number of new rules relating to arrays > of the same type but of different length, and using arrays of different > types. In particular, it would probably be necessary to special case > array of char so that even if two arrays are of different length, all > operations would work as if the str* functions had been called, i.e. > terminating on a 0 byte. > > The advantages of this proposal is that it adds something many > people feel has long been missing (array operations, passing arrays by ^^^^^^^^^^^^^^^ > value), but without overloading an existing operator or breaking any ^^^^^ > current code. No, what is missing from the language is the "concept" of input and output parameters. The user of the language should be insolated from the actually way parameters are passed around. It should be up to the compiler to determine whether an input parameter should be passed by reference or passed by value based on which ever method is faster for the particular parameter. The problems of passed by value for arrays is that the dimensions of the array are again generally unknown. > The disadvantages are that function calls would now require > the use of dope vectors, and assigments and comparisons would be > compound operations (i.e. a hidden loop); so what looks like a simple, > quick operation (like comparing two integers) could be a very long, > slow operation. Function call/return times also could increase. > > Well, so much for throwing out ideas. Any comments? > -- > Arnold Robbins > ARPA, CSNET: arnold@emory.ARPA BITNET: arnold@emory > UUCP: { decvax, gatech, sun!sunatl }!emory!arnold > ONE-OF-THESE-DAYS: arnold@emory.mathcs.emory.edu -- Eddie Wyatt e-mail: edw@ius1.cs.cmu.edu