• Yet another digression (was Re: [meta] O tempora, o mores! (was Re:does an expression in a logical statement need parenthesis for properevaluation?))

    From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.lang.c++,comp.lang.c on Mon Nov 23 11:06:21 2026
    From Newsgroup: comp.lang.c

    On 2026-11-22 18:04, Ross Finlayson wrote:

    [...] Then,
    for example there's "blank line at the end of a file or no blank line",

    (Note that your wording is expressing a shifted perspective.)

    for example Java-style has "no trailing line", here it's that
    the files always have a trailing empty line, then that for
    accounts like "cat all the files" that they're not ellided.

    I've never heard about "blank line at the end of a file". I
    suppose what you mean here is the effect that may be described:
    (a) every line should be terminated by a newline character,
    (b) some editors seem to display that proper line termination
    (for the last data line) as an empty line on their GUI.
    Note that this is an issue some editors introduce by their way
    of _representing_ a text, and not a property of the text data.

    A _file_ containing data (with line terminators '\n')
    line one\n
    line two\n
    ...
    last line\n
    has no "empty last line" (whatever your editor displays).

    The consequence of editors displaying a spurious empty line
    when all lines (including the last) are consistently terminated
    with a newline character is obviously that folks using such
    editors and have a tendency to consider a [spurious appearing]
    "empty line" as unnecessary ballast (and omit line termination)
    may run into problems like the 'cat' case you hinted on.

    Folks are free to use more sophisticated editors, or configure
    the ("misbehaving") editors to behave properly (if they allow
    that), or just live with the consequences (and disseminate that
    data problem further into the development team).

    Janis


    [...]

    --- Synchronet 3.21e-Linux NewsLink 1.2
  • From James Kuyper@jameskuyper@alumni.caltech.edu to comp.lang.c++,comp.lang.c on Mon Nov 23 23:15:54 2026
    From Newsgroup: comp.lang.c

    On 2026-11-23 05:06, Janis Papanagnou wrote:
    On 2026-11-22 18:04, Ross Finlayson wrote:

    [...] Then,
    for example there's "blank line at the end of a file or no blank line",

    (Note that your wording is expressing a shifted perspective.)

    for example Java-style has "no trailing line", here it's that
    the files always have a trailing empty line, then that for
    accounts like "cat all the files" that they're not ellided.

    I've never heard about "blank line at the end of a file".

    I no longer see Ross's messages directly, only what's quoted in other
    people's responses.

    Could he be referring to what the C standard says about text streams:

    "Whether the last line requires a terminating new-line character is implementation-defined." (7.24.2p2 n3998.pdf)

    I wouldn't describe that as "blank line or no blank line", but I could
    imagine it being misunderstood that way.

    The C++ standard defines the behavior of many fundamental <iostream>
    functions in terms of the C standard library's routines, so I suspect
    that this also applies to C++.
    --- Synchronet 3.21e-Linux NewsLink 1.2
  • From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.lang.c++,comp.lang.c on Tue Nov 24 07:40:52 2026
    From Newsgroup: comp.lang.c

    On 2026-11-24 05:15, James Kuyper wrote:
    On 2026-11-23 05:06, Janis Papanagnou wrote:
    On 2026-11-22 18:04, Ross Finlayson wrote:

    [...] Then,
    for example there's "blank line at the end of a file or no blank line",

    (Note that your wording is expressing a shifted perspective.)

    for example Java-style has "no trailing line", here it's that
    the files always have a trailing empty line, then that for
    accounts like "cat all the files" that they're not ellided.

    I've never heard about "blank line at the end of a file".

    I no longer see Ross's messages directly, only what's quoted in other people's responses.

    Could he be referring to what the C standard says about text streams:

    As what he writes appears often a bit convoluted it's not clear to
    me whether he was implicitly referring to the C-standard. There
    was no explicit reference to the C-standard (as far as I recall).

    Given the wording and context as presented (Tabs vs. Spaces, long
    lines, and meta-rambling etc.) it appeared more to be a statement
    about editors; data representation, files, the editors' GUIs. All
    somehow mixed in one (arguable; at least imprecise) statement. If
    we know (and spell out) these differences readers may get aware of
    the potential problems and act accordingly (which was my point).


    "Whether the last line requires a terminating new-line character is implementation-defined." (7.24.2p2 n3998.pdf)

    Working in POSIX environments, though, we have the certainty and we
    need not rely on the (yet another) uncertainty that the C-standard
    exposes here.

    (Personally I'm not much concerned as I'm always creating terminated
    lines in text-files. I'm also using an editor where the editor cares
    about detecting and creating correct representations in files, and
    which facilitates me to control that in (very rare) cases where I'd
    need it.)


    I wouldn't describe that as "blank line or no blank line", but I could imagine it being misunderstood that way.

    Given the representations of his thoughts it's easy to misunderstand
    his intention. Any answers will have to consider the thereby induced uncertainty.


    The C++ standard defines the behavior of many fundamental <iostream> functions in terms of the C standard library's routines, so I suspect
    that this also applies to C++.

    Janis

    --- Synchronet 3.21e-Linux NewsLink 1.2
  • From Ross Finlayson@ross.a.finlayson@gmail.com to comp.lang.c++,comp.lang.c on Tue Nov 24 08:37:19 2026
    From Newsgroup: comp.lang.c

    On 11/23/2026 08:15 PM, James Kuyper wrote:
    On 2026-11-23 05:06, Janis Papanagnou wrote:
    On 2026-11-22 18:04, Ross Finlayson wrote:

    [...] Then,
    for example there's "blank line at the end of a file or no blank line",

    (Note that your wording is expressing a shifted perspective.)

    for example Java-style has "no trailing line", here it's that
    the files always have a trailing empty line, then that for
    accounts like "cat all the files" that they're not ellided.

    I've never heard about "blank line at the end of a file".

    I no longer see Ross's messages directly, only what's quoted in other people's responses.

    Could he be referring to what the C standard says about text streams:

    "Whether the last line requires a terminating new-line character is implementation-defined." (7.24.2p2 n3998.pdf)

    I wouldn't describe that as "blank line or no blank line", but I could imagine it being misunderstood that way.

    The C++ standard defines the behavior of many fundamental <iostream> functions in terms of the C standard library's routines, so I suspect
    that this also applies to C++.



    I know what I meant, it doesn't take a generous reading to see
    that's what's _relevant_ as an example.


    The generous vis-a-vis the in-generous reading has that usual
    accounts like for "Grice" again or "effective communication",
    here has that having a "blank line" at the end of a compilation
    unit's sources, is usually considered a reasonable thing, vis-a-vis,
    for example, using line-oriented data and where either line-endings
    or end-of-file are record-separators, and _not_ having blank lines,
    i.e., there are settings where the last character in the file
    being a newline (i.e., resulting a "blank line", in the generous
    reading, for a line-reader that interprets either line-endings
    or end-of-file as record-separators and, well, end-of-file),
    is allowed, and settings where it ain't, that then in source files,
    about which various opinionated pretty-printers eventually have
    an option someone will tweak (and, generally it's a rule that
    "tweakers are un-reliable"), finding a chance to save one character-set character-set-encoding language's/system's newline or line-ending,
    like people who can't stand semi-colons as statement-endings,
    then has that people who omit the Oxford, standard, Harvard,
    serial comma: are considered slights to the language.



    I'm not dis-interested your opinion, haven't much heard of it.
    Perhaps you have subtler influences than I'd otherwise infer.



    --- Synchronet 3.21e-Linux NewsLink 1.2
  • From Keith Thompson@Keith.S.Thompson+u@gmail.com to comp.lang.c++,comp.lang.c on Tue Nov 24 16:50:14 2026
    From Newsgroup: comp.lang.c

    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    On 2026-11-24 05:15, James Kuyper wrote:
    [...]
    "Whether the last line requires a terminating new-line character is
    implementation-defined." (7.24.2p2 n3998.pdf)

    Working in POSIX environments, though, we have the certainty and we
    need not rely on the (yet another) uncertainty that the C-standard
    exposes here.

    (Personally I'm not much concerned as I'm always creating terminated
    lines in text-files. I'm also using an editor where the editor cares
    about detecting and creating correct representations in files, and
    which facilitates me to control that in (very rare) cases where I'd
    need it.)
    [...]

    Here's what POSIX says.

    https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap03.html

    3.185 Line
    A sequence of zero or more non-<newline> characters plus a
    terminating <newline> character.

    3.387 Text File
    A file that contains characters organized into zero or more
    lines. The lines do not contain NUL characters and none can
    exceed {LINE_MAX} bytes in length, including the <newline>
    character. Although POSIX.1-2024 does not distinguish between
    text files and binary files (see the ISO C standard), many
    utilities only produce predictable or meaningful output when
    operating on text files. The standard utilities that have such
    restrictions always specify "text files" in their STDIN or
    INPUT FILES sections.

    So as far as C is concerned, a non-empty file not ending in a newline
    may or may not be a text file, but in POSIX it is not. And yes,
    many tools will, at least by default, ensure that a created or
    updated non-empty text file will end with a newline character.

    But there are text-like files that don't end in a newline character
    (or that have lines exceeding LINE_MAX bytes), and I expect the
    tools I use to deal with such files reasonably, even if POSIX
    does't require it.
    --
    Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
    void Void(void) { Void(); } /* The recursive call of the void */
    --- Synchronet 3.21e-Linux NewsLink 1.2
  • From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.lang.c++,comp.lang.c on Wed Nov 25 09:59:14 2026
    From Newsgroup: comp.lang.c

    On 2026-11-25 01:50, Keith Thompson wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    On 2026-11-24 05:15, James Kuyper wrote:
    [...]
    "Whether the last line requires a terminating new-line character is
    implementation-defined." (7.24.2p2 n3998.pdf)

    Working in POSIX environments, though, we have the certainty and we
    need not rely on the (yet another) uncertainty that the C-standard
    exposes here.

    (Personally I'm not much concerned as I'm always creating terminated
    lines in text-files. I'm also using an editor where the editor cares
    about detecting and creating correct representations in files, and
    which facilitates me to control that in (very rare) cases where I'd
    need it.)
    [...]

    Here's what POSIX says.
    [snip]

    Yes, that's what I was referring to.


    So as far as C is concerned, a non-empty file not ending in a newline
    may or may not be a text file, but in POSIX it is not. And yes,
    many tools will, at least by default, ensure that a created or
    updated non-empty text file will end with a newline character.

    But there are text-like files that don't end in a newline character

    (There are text files that don't have CRs, NLs, or CR-NL at all!
    Have a look at fixed record files on mainframes. And then there's
    also occasionally been "end-of-file characters" on some systems.)

    You may introduce, beside [POSIX] text-file and [non-text] binary
    file, a third category "text-like" files, but that doesn't add
    anything but confusion about what those files characterize beyond
    the two categories given and is at best suitable to "explain" any
    deviation from the terms that abstain from "like" descriptions.

    (or that have lines exceeding LINE_MAX bytes), and I expect the
    tools I use to deal with such files reasonably, even if POSIX
    does't require it.

    If you're operating only with tools in an own ecosystem you will
    likely not observe any problems. Problems arise if your data has
    to be processed with different tools (and also across different
    platforms).

    HTH.

    Janis
    --- Synchronet 3.21e-Linux NewsLink 1.2
  • From Tristan Wibberley@tristan.wibberley+netnews2@alumni.manchester.ac.uk to comp.lang.c on Wed Nov 25 17:43:17 2026
    From Newsgroup: comp.lang.c

    On 25/11/2026 00:50, Keith Thompson wrote:
    Here's what POSIX says.

    https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap03.html

    3.185 Line
    A sequence of zero or more non-<newline> characters plus a
    terminating <newline> character.

    3.387 Text File
    A file that contains characters organized into zero or more
    ...



    But there are text-like files that don't end in a newline character
    (or that have lines exceeding LINE_MAX bytes), and I expect the
    tools I use to deal with such files reasonably, even if POSIX
    does't require it.


    Interestingly 'file(1)' here doesn't describe the largest text file as a
    text file even with -k, but it would be useful to recognise and report
    it as such.

    $ cpp -include limits.h -P <<<LINE_MAX
    2048
    $ wc -l *file
    1 bigtextfile
    1 toobigfile
    2 total
    $ wc -c *file
    2048 bigtextfile
    2049 toobigfile
    4097 total
    $ xxd bigtextfile | tail -n2
    000007e0: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa
    000007f0: 6161 6161 6161 6161 6161 6161 6161 610a aaaaaaaaaaaaaaa.
    $ xxd toobigfile | tail -n2
    000007f0: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa
    00000800: 0a .
    $ file -k *file
    bigtextfile: ASCII text, with very long lines (2047)
    toobigfile: ASCII text, with very long lines (2048)

    Note I read the specification as LINE_MAX bytes including the newline character.

    Interestingly the spec says "bytes" not "characters". I wonder if it is
    using the age-old definition of "byte" being the size of a character (as
    in C) or the modern popular one of "octet".
    --
    Tristan Wibberley

    The message body is Copyright (C) 2026 Tristan Wibberley except
    citations and quotations noted. All Rights Reserved except that you may,
    of course, cite it academically giving credit to me, distribute it
    verbatim as part of a usenet system or its archives, and use it to
    promote my greatness and general superiority without misrepresentation
    of my opinions other than my opinion of my greatness and general
    superiority which you _may_ misrepresent. You definitely MAY NOT train
    any production AI system with it but you may train experimental AI that
    will only be used for evaluation of the AI methods it implements.
    --- Synchronet 3.21e-Linux NewsLink 1.2
  • From Kaz Kylheku@046-301-5902@kylheku.com to comp.lang.c on Wed Nov 25 18:44:34 2026
    From Newsgroup: comp.lang.c

    On 2026-11-25, Tristan Wibberley <tristan.wibberley+netnews2@alumni.manchester.ac.uk> wrote:
    Note I read the specification as LINE_MAX bytes including the newline character.

    Interestingly the spec says "bytes" not "characters". I wonder if it is
    using the age-old definition of "byte" being the size of a character (as
    in C) or the modern popular one of "octet".

    LINE_MAX has to be in bytes probably because it's connected to the idea
    of being able to define a buffer large enough to hold a line that is
    within the LINE_MAX limit.

    If LINE_MAX were given in characters, then you have to think about the
    worst case actual buffer size in a given multi-byte encoding.
    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca
    --- Synchronet 3.21e-Linux NewsLink 1.2