Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Text Files Date: Fri, 16 Feb 2018 15:14:45 -0800 Organization: None to speak of Lines: 58 Message-ID: References: <5a8459d1$0$707$14726298@news.sunsite.dk> <87mv0b9ocq.fsf@bsb.me.uk> <61abd898-60fc-4290-823a-a7ddd264700e@googlegroups.com> <0c04c390-ed12-4844-95d4-1790cee90c33@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="6f83efc23bf5f10533d14661db20aa68"; logging-data="4756"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18acm8dS0xGwR65kd49TJ+g" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:ZrQjT+lvP3jZBuL+LAz/HKi0MFw= sha1:0pJnT7aS4HWEBAYUObp9xxwphAg= Xref: csiph.com comp.lang.c:126818 supercat@casperkitty.com writes: > On Friday, February 16, 2018 at 6:57:06 AM UTC-6, Bart wrote: >> I gave an example before of where an older language of mine (one of >> those involved above), statically typed like C, could do exactly this: >> >> int a,b,c,d,e,f >> readln #file, a,b,c,d,e,f >> >> There is no reason why C couldn't do exactly the same. Then it could be >> used for quick throwaway programs just as easily as any other language. > > A compiler using a purpose-designed library could probably generate code > to handle variadic arguments that was type-safe while being, in many > typical scenarios, more compact than what a C compiler would generate. > Given something like > > WriteLn('The values are x=', x, ' and y=', y, '.); > > a compiler could generate code equivalent to: > > { > char writeLnSpec8675309[] = {...}; > WriteLn(writeLnSpec8675309); > } > > where writeLnSpec8675309 would encode information about the types and > addresses of the objects to be printed as well as any format specifiers. > Such information could in many cases be more compact than the instructions > that would be needed to push the values in question onto the stack. Perhaps -- but what if you want more than one way to format a value of a given type? C provides multiple ways to format integer values on output. You can control the base, field width, leading zeros, etc. The cost is a lack of type safety (though compilers can do some checking *if* the format string is a literal). C++ is simpler for simple cases, but the standard way to change how values are formatted changes the state of the output stream. Print one integer in hexadecimal, and all following integers are printed in hexadecimal unless you explicitly reset the state. I have some vague thoughts about better approaches, but they wouldn't be topical. > The biggest problem with such an approach would be defining a means of > indicating what things were passed that would promote compatibility among > different tools, and yet lead to efficient code. Having the first thing > in each argument spec be a pointer to a descriptor which contains a > table of functions to examine arguments would be good for compatibility, > but add extra overhead. -- 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"