STEINBERGER@SRI.COM (Richard Steinberger) (08/04/87)
I'm a fairly new C language user and I apologize in advance if this question has an obvious answer. It concerns the use of CALLOC, the memory allocating function. On page 9-3 of the VAX C Run Time Reference Library the syntax is described as: #include stdlib void *calloc(size_t number, size_t size); My understanding of ANSI C is that a new use for the VOID keyword is that it can refer to a function that can return a pointer to any data type and thus obviate the need for casting. I tried using the CALLOC function (with the #include stdlib, which the compiler couldn't find). The compiler wouldn't accept this form, declaring something about void refering to functions that return no arguments (a more "standard" usage for void). I looked on page D-5 of the same manual where it describes the syntax as: char *calloc(unsigned number, unsigned size); I was able to get this to work when I declare and use them as follows: int number, *integer_ptr; char *calloc(); . . integer_ptr = (int *) calloc(number, sizeof(int)); . . My questions are: Is there an error on page 9-3 (as it conflicts with page D-5), or am I just not understanding how to use the CALLOC with the void keyword? Where, if anywhere, are the size_t data types defined? I used: #include stdlib and the compiler was unable to find it. What's wrong here? In short, what's the best way to use the CALLOC function? Thanks to all who reply. -Ric Steinberger steinberger@kl.sri.com -------
LEICHTER-JERRY@YALE.ARPA (08/05/87)
[The author reports problems with VAX C; the compiler complains that it can't find stdlib, and won't accept (void *)] Both of these are new to VAX C V2.3. It sure sounds from your description as if you are using an earlier version of the compiler! Note that even if you get the new compiler, the run time system comes with VMS. Some of the functions listed in the run-time documentation aren't there until VMS V4.6. -- Jerry -------