Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Help on this typedef Date: Fri, 12 May 2017 09:38:29 -0700 Organization: None to speak of Lines: 47 Message-ID: References: <8ad1e08b-bdf9-4baa-a8b4-63bf48fb3e3d@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="2da6e6b2a541d2172fa4d68cd264302d"; logging-data="25137"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ywq8cYahICTxffW3CRABe" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:jxdCG1GnB4NsW8rltZW9/or6W1E= sha1:rOVY9kgQt6lpMDVIMUVxs2cN98M= Xref: csiph.com comp.lang.c:109849 David Brown writes: > On 11/05/17 17:35, supercat@casperkitty.com wrote: >> On Thursday, May 11, 2017 at 3:04:00 AM UTC-5, David Brown wrote: >>> On 11/05/17 05:11, Keith Thompson wrote: >>>> I suspect that this is used to achieve a kind of semi-fake >>>> pass-by-reference semantics. >>> >>> An alternative possibility is that the array size in this code was not >>> always 1, or that the author thinks it might not always be 1 in the future. >> >> Using a literal 1 within a typedef in that case would seem unusual. > > It would be better to have: > > #define noOfMPZs 1 > > and use that rather than "1" in the typedef. > > But we don't know the origin of the code, or how well thought-out it is, > or what might have been put in as a quick hack. We are just guessing. It's from GMP, the GNU multiple precision arithmetic library. Quoting its documentation: When a GMP variable is used as a function parameter, it's effectively a call-by-reference, meaning if the function stores a value there it will change the original in the caller. Parameters which are input-only can be designated `const' to provoke a compiler error or warning on attempting to modify them. When a function is going to return a GMP result, it should designate a parameter that it sets, like the library functions do. More than one value can be returned by having more than one output parameter, again like the library functions. A `return' of an `mpz_t' etc doesn't return the object, only a pointer, and this is almost certainly not what's wanted. (An alternative might have been to make mpz_t a small struct, and require explicit pointers to simulate pass-by-reference.) -- 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"