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: Portable 16 bit binary integer write Date: Sun, 25 Sep 2016 15:17:08 -0700 Organization: None to speak of Lines: 29 Message-ID: References: <50a1e8f4-4fb3-4491-97d0-54768bf28685@googlegroups.com> <0b757bbb-0494-44cb-bd5a-26f117aaa404@googlegroups.com> <2cf666d7-0755-4c70-adad-07dbafc2b2e7@googlegroups.com> <09cb4413-16a6-4b63-89d0-9dafe56562f6@googlegroups.com> <68e53f3a-5fcc-44fc-90c4-bcf8dc3db680@googlegroups.com> <87y42ge0gy.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="30697"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+E+fKiEdc9UCcsoqk/pgEx" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:HfLE5ACBenUoGAXOcfIRlLa7y8M= sha1:Hqg86hCu1vm2xMMODkMfMZiZB58= Xref: csiph.com comp.lang.c:94059 supercat@casperkitty.com writes: > On Sunday, September 25, 2016 at 5:29:57 AM UTC-5, Ben Bacarisse wrote: >> Or you could have two functions and use a format specifier. That could >> be made considerably more flexible. And, at the expense of a bit more >> bloat, one could even add this to printf/scanf families. > > Back around 1990 I remember thinking there should be printf/scanf-like > functions for binary data (they'd need to be separate functions because > printf and scanf aren't designed to accommodate data that may contain > zero bytes, newlines, etc. printf("%c", 0) prints a null byte. putchar('\n') prints a newline. What's the problem? You can't have an embedded null character in a format string or in a string pointed by an argument corresponding to a "%s" format, but apart from that fprintf and fscanf certainly can deal with zero bytes and newline. It's not common to use fprintf with a binary stream, but it's well defined. (I'm assuming that you're really referring to fprintf and fscanf, and not literally to printf and scanf which work with stdout and stdin, which are opened in text mode.) [...] -- 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"