Path: ...!goblin2!goblin.stu.neva.ru!aioe.org!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: anton@mips.complang.tuwien.ac.at (Anton Ertl) Newsgroups: comp.arch Subject: Re: Why so many discussions about C was Re: The glory of optimizing compilers Date: Sat, 18 Apr 2020 16:38:28 GMT Organization: Institut fuer Computersprachen, Technische Universitaet Wien Lines: 104 Message-ID: <2020Apr18.183828@mips.complang.tuwien.ac.at> References: <1d732eab-688f-4719-a5b5-a04d4233865e@googlegroups.com> <865zdz8i55.fsf@linuxsc.com> <2020Apr17.133734@mips.complang.tuwien.ac.at> Injection-Info: reader02.eternal-september.org; posting-host="52e9d91edae6fde25994c4ea7dba499a"; logging-data="23156"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Ble4swFX8lacRwi0OOeFJ" Cancel-Lock: sha1:Ii/4t7RbBENuCIOuZh36eDIDqkk= X-newsreader: xrn 10.00-beta-3 Bytes: 5498 Stephen Fuld writes: >On 4/17/2020 4:37 AM, Anton Ertl wrote: >> Stephen Fuld writes: >>> I don't think we disagree at all. If C had included easy to use syntax >>> that caused especially numerical outputs to be displayed with things >>> like digit separators, >> >> Does not appear that hard: >> >> #include >> #include >> #include >> >> int main(int argc, char *argv[]) >> { >> long long n=strtoll(argv[1],NULL,10); >> setlocale(LC_NUMERIC, ""); >> printf("%'lld\n",n); >> return 0; >> } >> >> With an appropriate setting of the environment variable LC_NUMERIC (or >> LANG), you get thousands separators; e.g.: >> >> LC_NUMERIC=en_US.utf8 a.out 2325895923 >> >> prints >> >> 2,325,895,923 >> >> (note that you must have that locale installed on your system in order >> for it to work). > > >OK, but then why to we see so many large numbers without "proper" >formatting? Are these features relatively recently added to most >compilers? Is it just part of the "C Culture"? It is not part of the C culture (if such a thing exists) to print numbers with thousands separators; you don't see it done in the textbooks. This is the first time I have used setlocale or the "'" printf specifier (and the perverse part is that you need to use both or it won't work; why is it not enough if I just include the "'" specifier?). >>> then programmers would have used it, and >>> designers like you would have seen it in lots of places and included >>> features in the architecture to to make that easy. >> >> No, they would not. .... >If the "not" referred to including architectural support, then I >probably agree. It refers to architectural support. >But this was less true than it is now in the period of >the ascending influence of C. But since this was also the era of RISC >dominance, and such features are definitely not RISC, then you are >probably right. Yes, a while ago I examined and refuted the thesis that the architectures were designed for C. I am too lazy to search for my more elaborate posting, but IIRC my main points were: 1) Many architectures were designed before C became dominant. And in some cases we know the languages that were looked at when designing the architecture; e.g., for the IBM 801 it was PL/8 (a PL/I subset), ARM was designed by assembly programmers, MIPS used benchmarks written in Pascal, and the HPPA designers used code from its existing HP 1000 (AFAIK Pascal), HP 3000 (probably COBOL and such), and HP 9000 lines (probably C there). 2) The architectures that were designed after C became dominant do not look that different from architectures that were designed before. One other aspect is that some C-specific idioms, in particular zero-terminated strings, have resulted in remarkably little architectural support. True=1 is quite common, but already present in MIPS, and Aarch64 supports True=-1 as well as it supports True=1. >> Interestingly, I use LC_NUMERIC=C by default (which suppresses >> thousands separators), because I often copy and paste nunbers into >> other programs, and the other programs usually choke on thousands >> separators. > > >Valid point. But that is certainly not the only use. I wonder how >often people do this, say as a percentage of the large numbers printed? It's not that often, but it's more annoying to try to copy a number with thousands separators that to read one without; I often help myself by highlight three digits with the mouse. In any case, this points to the main problem not being what programs print, but what programs accept as inputs. If C's atoi/strtol etc. accepted thousands separators, we might be seeing many more programs that output thousands separators. - anton -- M. Anton Ertl Some things have to be seen to be believed anton@mips.complang.tuwien.ac.at Most things have to be believed to be seen http://www.complang.tuwien.ac.at/anton/home.html