Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!godot!harvard!seismo!brl-tgr!gwyn From: gwyn@brl-tgr.ARPA (Doug Gwyn ) Newsgroups: net.lang.c Subject: Re: limitations of casts, pointer and function declarartions... Message-ID: <5487@brl-tgr.ARPA> Date: Sun, 28-Oct-84 21:48:15 EST Article-I.D.: brl-tgr.5487 Posted: Sun Oct 28 21:48:15 1984 Date-Received: Tue, 30-Oct-84 01:16:16 EST References: <120@harvard.ARPA> Distribution: net Organization: Ballistic Research Lab Lines: 38 > int x; > char *y; > /*### [cc] illegal lhs of assignment operator = %%%*/ > (char *)x = y; You need an lvalue, not an expression, on the LHS. > typedef ref *ref; All types must reduce to a basic type (void, char, short, int, long, float, double, struct/union) plus some number of operators (*, (), []). > The point is that if a pointer of this type is dereferenced, it should > have the same type again. In addition, the type should be cast'able > to/from integer, and the size associated with it should be that of a > single pointer of its kind. At present, the generic pointer type is (char *) (ANSI will probably change this to (void *)). A (char *) is castable to a (long) and back without loss of information (note: NOT always to an (int)). By using appropriate type casts you can use the contents of a (char *) or (long) for other purposes. > Along the same lines, I'd like to be able to define a function > returning a pointer to its own kind, i.e. > > typedef fun (*fun)(); Ditto. C is a typed language. To implement another, untyped, language (or one with types that do not reduce to basic types) in C you must pick a definite C data type to represent objects in the other language (in this case, ProLog). Then you need to coerce data into the appropriate types via typecasts when implementing recursive types etc. C lets you do this but you have to explicitly indicate that you are playing tricks with data types. (With some C implementations you can be pretty sloppy, but for portable code follow the type rules and run everything past "lint".)