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 23:23:03 -0800 Organization: None to speak of Lines: 56 Message-ID: References: <0e1db67d-0ab8-4971-a319-8aa66a40b873@googlegroups.com> <87inr7i1kv.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="a5363bb21fe375e056a99c05fd10e589"; logging-data="16729"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/TAWSPSrDFW7qFguhmHQRD" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:rHFHaRZSiCWDG9v0uIJPGIVUooA= sha1:K5uT0+NU0fKwi8Sq8Bd8wGsM5PM= Xref: csiph.com comp.lang.c:97710 BartC writes: > On 29/11/2016 00:14, Ben Bacarisse wrote: >> 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 >> >> No it can't. > > Yes it can; that's what the code is doing. > > s is used to refer to a string. Yes, s is used to refer to a string. s is not a string. s is a pointer. You understand that, but you spread confusion by pretending not to. Stop it. > n is a number. Yup. (More precisely an integer, even more precisely an object of type int). > The language allows you to add those together using 's + n'. Yes, you can add a pointer and an integer, with semantics that have been discussed at length. > Of course the actual operation it does, because of how C works, is not > very interesting: it takes the address of the start of the string, and > steps it by 5. It doesn't end up with "Hello world5" or, after trying to > convert "Hello World" to number and getting 0, adding 5 to that. Oh? I'd call it very interesting. It's at the core of how C deals with arrays and their elements. Of course you pretend not to understand that because it helps you spread confusion. > But then exactly what 'add number to a string' does hasn't been defined. No, it hasn't, because it doesn't make any sense. Please stop making things up. C can be confusing enough. Stop trying to make it worse. [...] -- 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"