Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Some kind of contextual modulo operator? Date: Fri, 01 Dec 2017 08:56:40 -0800 Organization: None to speak of Lines: 33 Message-ID: References: <8baec7c1-5c5e-4391-b011-9317ff220752@googlegroups.com> <1679454a-2d88-4821-be92-a73dba4d4d75@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="ccf519c238b83d58af35e4f4ed341a14"; logging-data="16868"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19DoJPDWwSexHHXw1D5Cnxh" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:ZwOpNuJmXvyeBlG0lwVpBxPEXWE= sha1:kjsGD0uGKi0221ZvZT7JL1Dpk6U= Xref: csiph.com comp.lang.c:123677 bartc writes: [...] > A further point about malloc: I generally call it as a foreign function, > with its parameter defined as either a 32-bit or 64-bit signed integer. > > Not that I ever intend to pass it negative values, but that I don't > expect to pass parameters which are 2**31 or above, or 2**63 or above. > > On Windows, in 32-bit mode on x86, I don't think you can make a single > allocation above 2**31 (and the limit is reduced further by the fact > that some of the 2GB virtual address space is already occupied by the > running program and any previous allocations). > > While in 64-bit mode, a single allocation of some 9 billion GB would be > unlikely to succeed. > > So you wouldn't lose much by not using 'size_t' in these cases. If you use a 32-bit signed integer, then (a) you lose the ability to allocate 2GB or more (which I just did successfully on a small test program), and (b) if you're calling it as a foreign function and you get the size of the argument wrong, the call might not work at all. I understand that calling malloc() as a foreign function is more complicated than calling it from C. I don't understand why you'd deliberately use a signed argument for a function that takes an unsigned argument. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"