Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!pyramid!thirdi!peter From: peter@thirdi.UUCP (Peter Rowell) Newsgroups: comp.lang.c Subject: type casting Message-ID: <400@thirdi.UUCP> Date: 27 Apr 88 20:48:17 GMT Reply-To: peter@thirdi.UUCP (Peter Rowell) Organization: Third Eye Software, Inc., Menlo Park, CA Lines: 33 Keywords: type casting I have two questions regarding type casting. Both of them arise from the need to improve the appearance of some code, probably using #define's. It is important that the code compile on a *very* wide assortment of machines/compilers with no compile errors and no lint errors. 1) Is type casting of the left hand side of an expression supported in ANSI C? Any place other than BSD? E.g. int *pfoo; (char *)pfoo = malloc(10*sizeof(pfoo[0])); 2) Is it possible to use a variable in such a way as to imply its type for casting purposes? E.g. int *pfoo; pfoo = (typeof(pfoo)) malloc(10*sizeof(pfoo[0])); We would like to do something like: #define AdjustArray(arr,cnt) \ ((char *)arr = realloc((char *)arr, cnt * sizeof(arr[0]))) OR #define AdjustArray(arr,cnt) \ (arr = (typeof(arr)) realloc((char *)arr, cnt * sizeof(arr[0]))) and then replace pfoo = (int *) realloc((char *)pfoo, new_size * sizeof(pfoo[0])); with AdjustArray(pfoo, new_size); Replies by mail, please. Peter Rowell Third Eye Software, Inc. (415) 321-0967