Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!ames!ucbcad!ucbvax!decvax!decwrl!hplabs!sdcrdcf!trwrb!aero!venera.isi.edu!lmiller From: lmiller@venera.isi.edu.UUCP Newsgroups: comp.lang.c,news.software.b Subject: Re: passing NULL to functions Message-ID: <2671@venera.isi.edu> Date: Wed, 6-May-87 12:16:47 EDT Article-I.D.: venera.2671 Posted: Wed May 6 12:16:47 1987 Date-Received: Sat, 9-May-87 06:21:52 EDT References: <150@sds.UUCP> <1129@ius2.cs.cmu.edu> <5804@brl-smoke.ARPA> <4724@utcsri.UUCP> <728@sdchema.sdchem.UUCP> Reply-To: lmiller@venera.isi.edu.UUCP (Larry Miller) Organization: Information Sciences Institute, Univ. of So. California Lines: 36 Xref: utgpu comp.lang.c:2019 news.software.b:574 In article <728@sdchema.sdchem.UUCP> tps@sdchemf.UUCP (Tom Stockfisch) writes: >In article <4724@utcsri.UUCP> greg@utcsri.UUCP (Gregory Smith) writes: > >>>In article <1129@ius2.cs.cmu.edu> edw@ius2.cs.cmu.edu (Eddie Wyatt) writes: > >>>>#define alloc(type) ((type *) malloc(sizeof(type))) > >>...problem...is that (type *) is not always a >>cast to pointer to type: e.g. int (*)() means pointer to func returning int, >>but ( int (*)() * ) means you get a syntax error. >> >>There is no cure for this; it is a result of C's bass-ackward type syntax. > >>Greg Smith University of Toronto UUCP: ..utzoo!utcsri!greg ETC. The type of (int (*)()) is "pointer to function returning int". If this is the type in the allocation (type *) malloc(sizeof(type)), then we're allocating space for a "function returning int". I don't think we can do that. Here's a little prorgram, and the output of lint (4.3 UNIX on VAX 8650). #include main() { int (*x)(); /* ptr to function returning int */ x = (int (*)()) malloc (sizeof (int ()); } test.c: test.c(6): compiler error: compiler takes size of function Larry Miller lmiller@venera.isi.edu