White space at the end of a line

Discussion in 'C Programming' started by Spiros Bousbouras, Dec 3, 2007.

  1. I'm thinking of adding a command to vim for removing
    white space from the end of each line of a C source
    file. Can anyone think of a situation where such white
    space might be useful ?
     
    Spiros Bousbouras, Dec 3, 2007
    #1
    1. Advertising

  2. Spiros Bousbouras

    Guest

    On Dec 3, 7:52 pm, Spiros Bousbouras <> wrote:
    > I'm thinking of adding a command to vim for removing
    > white space from the end of each line of a C source
    > file. Can anyone think of a situation where such white
    > space might be useful ?


    //\<no-space>
    printf("Never called!\n");
    //\<space>
    printf("Called!\n");
     
    , Dec 3, 2007
    #2
    1. Advertising

  3. In article <>,
    <> wrote:

    >> I'm thinking of adding a command to vim for removing
    >> white space from the end of each line of a C source
    >> file. Can anyone think of a situation where such white
    >> space might be useful ?


    >//\<no-space>
    >printf("Never called!\n");
    >//\<space>
    >printf("Called!\n");


    He said "useful", not "obfuscating"!

    -- Richard
    --
    "Consideration shall be given to the need for as many as 32 characters
    in some alphabets" - X3.4, 1963.
     
    Richard Tobin, Dec 3, 2007
    #3
  4. On Dec 3, 5:58 pm, wrote:
    > On Dec 3, 7:52 pm, Spiros Bousbouras <> wrote:
    >
    > > I'm thinking of adding a command to vim for removing
    > > white space from the end of each line of a C source
    > > file. Can anyone think of a situation where such white
    > > space might be useful ?

    >
    > //\<no-space>
    > printf("Never called!\n");
    > //\<space>
    > printf("Called!\n");


    I wouldn't call a construct like

    //\<no-space>
    printf("Never called!\n");

    useful. But thanks for the suggestion.
     
    Spiros Bousbouras, Dec 3, 2007
    #4
  5. On Mon, 3 Dec 2007 09:52:17 -0800 (PST), Spiros Bousbouras
    <> wrote:

    >I'm thinking of adding a command to vim for removing
    >white space from the end of each line of a C source
    >file. Can anyone think of a situation where such white
    >space might be useful ?


    Consider

    #define foo \<space>
    #define foo \<no_space>

    The behaviours are different.



    Richard Harter,
    http://home.tiac.net/~cri, http://www.varinoma.com
    In the fields of Hell where the grass grows high
    Are the graves of dreams allowed to die
     
    Richard Harter, Dec 3, 2007
    #5
  6. Spiros Bousbouras

    Al Balmer Guest

    On Mon, 03 Dec 2007 18:49:22 GMT, (Richard Harter) wrote:

    >On Mon, 3 Dec 2007 09:52:17 -0800 (PST), Spiros Bousbouras
    ><> wrote:
    >
    >>I'm thinking of adding a command to vim for removing
    >>white space from the end of each line of a C source
    >>file. Can anyone think of a situation where such white
    >>space might be useful ?

    >
    >Consider
    >
    >#define foo \<space>
    >#define foo \<no_space>
    >
    >The behaviours are different.
    >

    What Richard Tobin said.

    --
    Al Balmer
    Sun City, AZ
     
    Al Balmer, Dec 3, 2007
    #6
  7. Spiros Bousbouras <> writes:
    > I'm thinking of adding a command to vim for removing
    > white space from the end of each line of a C source
    > file. Can anyone think of a situation where such white
    > space might be useful ?


    As others have said, the example presented by vippstar isn't what I'd
    call *useful*, except perhaps to determine which programmer to fire.

    Before I saw that example, I would have guessed that there's no case
    where trailing white space is significant. One exception, sort of, is
    that a line-joining \ can't be followed by white space (which is a
    dumb rule IMHO), but in that case the white space makes the program
    illegal.

    However, depending on what text editor you use, it might be convenient
    to have blank lines indented by the same amount as the non-blank lines
    surrounding them. For example (end-of-line marked with '$'):

    int x;$
    $
    x = 42;$

    vs.

    int x;$
    $
    x = 42;$

    It makes no difference to the compiler, of course,

    --
    Keith Thompson (The_Other_Keith) <>
    Looking for software development work in the San Diego area.
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Dec 3, 2007
    #7
  8. (Richard Tobin) wrote:
    > <> wrote:
    > > > I'm thinking of adding a command to vim for removing
    > > > white space from the end of each line of a C source
    > > > file. Can anyone think of a situation where such white
    > > > space might be useful ?

    > >
    > >//\<no-space>
    > >printf("Never called!\n");
    > >//\<space>
    > >printf("Called!\n");

    >
    > He said "useful", not "obfuscating"!


    This isn't useful either...

    puts("Something with a \\<space>
    to illustrate a point.");

    --
    Peter
     
    Peter Nilsson, Dec 3, 2007
    #8
  9. Spiros Bousbouras

    CBFalconer Guest

    Spiros Bousbouras wrote:
    >
    > I'm thinking of adding a command to vim for removing white space
    > from the end of each line of a C source file. Can anyone think of
    > a situation where such white space might be useful ?


    Yes.

    --
    Chuck F (cbfalconer at maineline dot net)
    <http://cbfalconer.home.att.net>
    Try the download section.


    --
    Posted via a free Usenet account from http://www.teranews.com
     
    CBFalconer, Dec 3, 2007
    #9
  10. On Mon, 03 Dec 2007 09:52:17 -0800, Spiros Bousbouras wrote:

    > I'm thinking of adding a command to vim for removing
    > white space from the end of each line of a C source
    > file. Can anyone think of a situation where such white
    > space might be useful ?

    I can't, but of course a danger with such file modifications
    is that (some) source control systems/patchers might be fooled into
    thinking you had made many changes, for which others working
    on the same code might not thank you.
     
    Duncan Muirhead, Dec 4, 2007
    #10
  11. Spiros Bousbouras

    CBFalconer Guest

    Duncan Muirhead wrote:
    > Spiros Bousbouras wrote:
    >
    >> I'm thinking of adding a command to vim for removing
    >> white space from the end of each line of a C source
    >> file. Can anyone think of a situation where such white
    >> space might be useful ?

    >
    > I can't, but of course a danger with such file modifications is
    > that (some) source control systems/patchers might be fooled into
    > thinking you had made many changes, for which others working on
    > the same code might not thank you.


    I am not familiar with vim, but thi can probably be done without
    any alterations. Just use a macro.

    --
    Chuck F (cbfalconer at maineline dot net)
    <http://cbfalconer.home.att.net>
    Try the download section.



    --
    Posted via a free Usenet account from http://www.teranews.com
     
    CBFalconer, Dec 4, 2007
    #11
  12. "CBFalconer" <> schrieb im Newsbeitrag
    news:...
    > Duncan Muirhead wrote:
    >> Spiros Bousbouras wrote:
    >>
    >>> I'm thinking of adding a command to vim for removing
    >>> white space from the end of each line of a C source
    >>> file. Can anyone think of a situation where such white
    >>> space might be useful ?

    >>
    >> I can't, but of course a danger with such file modifications is
    >> that (some) source control systems/patchers might be fooled into
    >> thinking you had made many changes, for which others working on
    >> the same code might not thank you.

    >
    > I am not familiar with vim, but thi can probably be done without
    > any alterations. Just use a macro.

    Please expand on that, how could a macro (assuming you talk #define here)
    remove trailing whitespace from some source file?
    And how could it be added without modifying that source file?

    Bye, Jojo
     
    Joachim Schmitz, Dec 4, 2007
    #12
  13. Spiros Bousbouras

    Guest

    On Dec 4, 2:30 pm, "Joachim Schmitz" <>
    wrote:
    > "CBFalconer" <> schrieb im Newsbeitragnews:...> Duncan Muirhead wrote:
    > >> Spiros Bousbouras wrote:

    >
    > >>> I'm thinking of adding a command to vim for removing
    > >>> white space from the end of each line of a C source
    > >>> file. Can anyone think of a situation where such white
    > >>> space might be useful ?

    >
    > >> I can't, but of course a danger with such file modifications is
    > >> that (some) source control systems/patchers might be fooled into
    > >> thinking you had made many changes, for which others working on
    > >> the same code might not thank you.

    >
    > > I am not familiar with vim, but thi can probably be done without
    > > any alterations. Just use a macro.

    >
    > Please expand on that, how could a macro (assuming you talk #define here)
    > remove trailing whitespace from some source file?
    > And how could it be added without modifying that source file?
    >
    > Bye, Jojo


    You assumed wrong.
    Yes, it's OT to talk about vim macros.
    Theres a thin line between pedantry and stupidity.
     
    , Dec 4, 2007
    #13
  14. Spiros Bousbouras wrote:

    >I'm thinking of adding a command to vim for removing
    >white space from the end of each line of a C source
    >file.


    What is wrong with :%s/[\t ][\t ]*$// ? Just define it as a macro.

    > Can anyone think of a situation where such white
    >space might be useful ?


    No.

    (I do this all the time when comparing different
    versions of a file to avoid "false positives")

    Roberto Waltman

    [ Please reply to the group,
    return address is invalid ]
     
    Roberto Waltman, Dec 4, 2007
    #14
  15. Spiros Bousbouras

    Chris Torek Guest

    In article <>
    Spiros Bousbouras <> wrote:
    >I'm thinking of adding a command to vim for removing
    >white space from the end of each line of a C source
    >file. Can anyone think of a situation where such white
    >space might be useful ?


    As several people note, this requires defining "useful".

    I will add, here, that attempting to make use of "invisible" trailing
    white space in C programs, e.g., by writing a slash-slash comment
    (in C99) followed by a backslash followed by a blank followed by
    a newline, so that the line following this line appears to be
    commented out but actually is not, is a bad idea. This is the
    case not only because it is obfuscatory, but also because it may
    malfunction on some systems.

    There are still some (now rare) file systems Out There that are
    unable to distinguish between an "empty" line and a "line consisting
    only of blanks". In particular, they see a file as a set of
    "records" of fixed length. A line shorter than the fixed record
    length is blank-padded, and a line exactly the fixed record length
    is left alone. (It is physically impossible to have a line longer
    than the record length.) In other words, all lines are exactly
    the same length, hence the name "fixed length records".

    If a C compiler on such a system reads such files, it will[%] remove
    all "trailing blanks" from the file itself, as if you (the OP above)
    had used your vim command. So an attempt to use C99 comments to
    *pretend* to comment out the next line, on such a compiler, actually
    *will* comment out the next line. (One can thus use the attempt
    to discover whether the compiler is reading fixed-length records
    and stripping trailing whitespace from them.)

    [% Actually, it could also leave them in, giving surprising behavior
    for what the programmer *thought* were trailing backslashes. The
    systems I have heard of do delete trailing white-space, though, to
    avoid these surprises.]
    --
    In-Real-Life: Chris Torek, Wind River Systems
    Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
    email: forget about it http://web.torek.net/torek/index.html
    Reading email is like searching for food in the garbage, thanks to spammers.
     
    Chris Torek, Dec 5, 2007
    #15
  16. On Dec 4, 7:24 pm, Roberto Waltman <> wrote:
    > Spiros Bousbouras wrote:
    > >I'm thinking of adding a command to vim for removing
    > >white space from the end of each line of a C source
    > >file.

    >
    > What is wrong with :%s/[\t ][\t ]*$// ? Just define it as a macro.


    Nothing. It is one possibility but I'm thinking
    of something more elaborate perhaps. Whether it
    does anything will depend on whether a boolean
    option is set, possibly it will give a warning
    for each modified line and to take into account
    what Keith Thompson said possibly it will leave
    alone lines containing only white space.
     
    Spiros Bousbouras, Dec 5, 2007
    #16
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greg N.
    Replies:
    8
    Views:
    577
    Neredbojias
    Jul 28, 2005
  2. Shuo Xiang

    Stack space, global space, heap space

    Shuo Xiang, Jul 9, 2003, in forum: C Programming
    Replies:
    10
    Views:
    2,986
    Bryan Bullard
    Jul 11, 2003
  3. Ben C
    Replies:
    6
    Views:
    2,253
    Leif K-Brooks
    Jan 28, 2007
  4. j1c
    Replies:
    5
    Views:
    129
  5. Replies:
    2
    Views:
    135
Loading...

Share This Page