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: absence of max Date: Sat, 03 Dec 2016 11:08:41 -0800 Organization: None to speak of Lines: 78 Message-ID: References: <0e1db67d-0ab8-4971-a319-8aa66a40b873@googlegroups.com> <4894f89e-1b6a-4a7e-97b5-e12c9734da41@googlegroups.com> <8e947169-6c71-4977-b6fd-bb7a1185994b@googlegroups.com> <422c6643-4e2d-4b71-8937-434aad03bff9@googlegroups.com> <829f496b-0f0d-408c-82b3-8be2bd5775d7@googlegroups.com> <2bba48cd-e2c6-44f1-bce9-eff26acbba50@googlegroups.com> <37a4c69f-07eb-4e03-b548-7348629e6b3c@googlegroups.com> <71c8962e-b06e-44a5-8bda-a79d8cda48e5@googlegroups.com> <87y3zxkbhj.fsf@bsb.me.uk> <2eb6d201-e900-4866-a8e2-e13c5a74a5bb@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="7a8b968575d3efabfc24865b0e570486"; logging-data="25185"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+fY54+cUh7iduWLhtfmxlF" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:hjHYeKGqTH4U2hVLIjEIoe0DvSc= sha1:AkOzlHmA3GuoExS860Ylf7259dk= Xref: csiph.com comp.lang.c:97951 jameskuyper@verizon.net writes: > On Saturday, December 3, 2016 at 11:15:35 AM UTC-5, David Brown wrote: >> On 03/12/16 16:32, James R. Kuyper wrote: > ... >> > C2011 adds a feature that allows us to check this directly (which won't >> > necessarily convince Jerry, either): >> > >> > #include >> > #define TYPE(a) _Generic(a, \ >> > int*:"int *", int[4]:"int[4]", default:"other") >> > >> > typedef int thing[4]; >> > void foo(thing bar) >> > { >> > thing boz; >> > printf("%s:%s\n", "bar", TYPE(bar)); >> > printf("%s:%s\n", "boz", TYPE(boz)); >> > } >> > >> > int main(int argc, char *argv[]) >> > { >> > foo(&argc); >> > >> > return 0; >> > } >> > >> > Unfortunately, the compiler I currently have access to doesn't support >> > C2011. Therefore, I can't confirm whether I've used _Generic correctly, >> > nor can I confirm the results. Could someone who has a compiler that >> > does support _Generic() check this out? >> >> I had a look using , but it looks like both get >> printed as "int *". Maybe _Generic also turns arrays into int* like >> parameter passing? I don't know the details of _Generic well enough to >> tell. > > "Except when it is the operand of the sizeof operator, the _Alignof > operator, or the unary & operator, or is a string literal used to > initialize an array, an expression that has type ‘‘array of type’’ is > converted to an expression with type ‘‘pointer to type’’ that points > to the initial element of the array object and is not an lvalue." > (6.3.2.1p3) > > I think there should also have been an exception for _Generic, but > that's not what was actually done. Therefore, my suggestion is not as > useful as I thought it would be. But it can be made useful by taking the address of the operand: #include #define TYPE(a) _Generic(&a, \ int**:"int *", int(*)[4]:"int[4]", default:"other") typedef int thing[4]; void foo(thing bar) { thing boz; printf("%s:%s\n", "bar", TYPE(bar)); printf("%s:%s\n", "boz", TYPE(boz)); } int main(int argc, char *argv[]) { foo(&argc); return 0; } Output: bar:int * boz:int[4] -- 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"