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: Mon, 28 Nov 2016 21:05:57 -0800 Organization: None to speak of Lines: 38 Message-ID: References: <0e1db67d-0ab8-4971-a319-8aa66a40b873@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="a5363bb21fe375e056a99c05fd10e589"; logging-data="18083"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+lwDNWclarolEQlZHuK2O7" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:80dhX6qTrkpFhtXsxbxEHjz6Xac= sha1:4ibngInN+QlagemIQttaL9srwhQ= Xref: csiph.com comp.lang.c:97706 BartC writes: [...] > C allows this: > > char* s = "Hello world"; > int n = 5; > > printf("%s\n", s + n); > printf("%d\n", s + n); > printf("%p\n", s + n); > > So it can add a number to a string (and print the result as a string, > number or pointer). I guess that means C has weak typing; it doesn't try > too hard to stop you getting around its type system. The first and third examples do not demonstrate weak typing. The result of adding a char* value and an int value is of type char*. Permitting operators to have operands of different types is not weak typing. (Though "%p" requires a void* argument, and s + n is of type char*.) The second example does demonstrate weak typing, in a sense. In fact, that call has undefined behavior. printf is not required to *enforce* correct types for its arguments. I don't think there's any rigorous definition of the terms "weak typing" and "strong typing". I'd call C's typing somewhat "strong" in the sense that every expression has an unambiguous well-defined type. The major way in which I'd call C's typing "weak" is its widespread use of implicit conversions. [...] -- 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"