Path: utzoo!dciem!array!colin From: colin@array.UUCP (Colin Plumb) Newsgroups: comp.lang.c Subject: Re: Turbo C large character array Message-ID: <437@array.UUCP> Date: 9 Aug 90 06:21:43 GMT References: <1990Jul27.193520.4689@ux1.cso.uiuc.edu> <17ac63d1.ARN02634@xenon.stgt.sub.org> Distribution: comp Organization: Array Systems Computing, Inc., Toronto, Ontario, CANADA Lines: 40 In article <17ac63d1.ARN02634@xenon.stgt.sub.org> alf@xenon.stgt.sub.org (Ingo Feulner) writes: >But doesn't say the ANSI standard that malloc() mustn't allocate more than >64K once a time? (so says my Lattice C manual) If the ANSI committee had done something a tenth as brain-damaged, they'd be getting a large bundle of Semtex from me in the mail. The ANSI standard gives only MINIMUMS; it does not forbid an implementation that pads all objects to 4 gigabyte boundaries. malloc (4.10.3.3) takes an argument of type size_t. size_t (4.1.5) is the unsigned integral type of the result of the sizeof operator. The sizeof() operator (3.3.3.4) may be applied to any type or expression, and so size_t must be able to hold the size of the largest object declarable in the implementation. A hosted implementation (i.e. one that has malloc) must be able to trnaslate and execute a program that contains a 32767-byte object, according to 2.2.4.1, so that number, at least, must be passable to malloc. An integral type (3.1.2.5) is one of: char, signed char, unsigned char short int, unsigned short int int, unsigned int long int, unsigned long int an enumeration type. All enumeration types have the same internal representation as some other integral type, so we can basically ignore that. Thus, size_t must be one of unsigned char, unsigned short, unsigned int, or unsigned long. These must be pure binary (have maxima of the form 2^n-1), and n must be at least 8, 16, 16, and 32, respectively. So it is possible to have an implementation that uses 15-bit unsigned chars and the same type for size_t, thus making it impossible for malloc to allocate more memory than that. In practice, size_t had better be at least as big as uint, so malloc must take an argument up to 655535 (although it may return NULL). So, you've got a minimum, but there's no maximum. I can have a 64-bit size_t if I like. -- -Colin