Syntax for variable names spanning multiple lines in C

Discussion in 'C Programming' started by Sriram Rajagopalan, Nov 13, 2006.

  1. Hi,

    I was interested to know if there is a way to use a variable name split
    across multiple lines in C.

    For example :

    int this_is_a_very_long_variable_name = 10;

    I would like to split the "this_is_a_very_long_variable_name " into 2
    lines - lets say "this_is_a_" in the first line and
    "very_long_variable_name " in the second line.

    Is this possible syntactically in C?

    I tried using the backslash operator in vain :

    int this_is_a_\
    very_long_variable_name = 10;

    The above gives a compilation error.

    Please suggest the means to do this if there is any.

    Thanks,
    Sriram.
     
    Sriram Rajagopalan, Nov 13, 2006
    #1
    1. Advertising

  2. Sriram Rajagopalan

    Chris Dollin Guest

    Sriram Rajagopalan wrote:

    > I was interested to know if there is a way to use a variable name split
    > across multiple lines in C.


    There isn't.

    I'm curious as to what you're doing that needs this.

    --
    Chris "hantwig efferko VOOM!" Dollin
    "Who are you? What do you want?" /Babylon 5/
     
    Chris Dollin, Nov 13, 2006
    #2
    1. Advertising

  3. Sriram Rajagopalan

    Guest

    Hello Sriram,

    > I was interested to know if there is a way to use a variable name split
    > across multiple lines in C.
    >
    > For example :
    >
    > int this_is_a_very_long_variable_name = 10;
    >
    > I would like to split the "this_is_a_very_long_variable_name " into 2
    > lines - lets say "this_is_a_" in the first line and
    > "very_long_variable_name " in the second line.
    >
    > Is this possible syntactically in C?
    >
    > I tried using the backslash operator in vain :
    >
    > int this_is_a_\
    > very_long_variable_name = 10;


    don't put any blank or tab after the \
    don't put any blank or tab before "very_long_name"

    ex:
    int this_is_a_\
    very_long_variable_name = 10;

    HTH,
    Loic.
     
    , Nov 13, 2006
    #3
  4. Sriram Rajagopalan

    Random832 Guest

    2006-11-13 <>,
    Sriram Rajagopalan wrote:
    > Hi,
    >
    > I was interested to know if there is a way to use a variable name split
    > across multiple lines in C.
    >
    > For example :
    >
    > int this_is_a_very_long_variable_name = 10;
    >
    > I would like to split the "this_is_a_very_long_variable_name " into 2
    > lines - lets say "this_is_a_" in the first line and
    > "very_long_variable_name " in the second line.
    >
    > Is this possible syntactically in C?
    >
    > I tried using the backslash operator in vain :
    >
    > int this_is_a_\
    > very_long_variable_name = 10;
    >
    > The above gives a compilation error.


    int this_is_a_\
    very_long_variable_name

    No indentation is permitted when you are attempting to split a token in
    the middle, since \ does not eat any whitespace other than the
    immediately following newline.
     
    Random832, Nov 13, 2006
    #4
  5. Random832 wrote:
    > 2006-11-13 <>,
    > Sriram Rajagopalan wrote:
    > > Hi,
    > >
    > > I was interested to know if there is a way to use a variable name split
    > > across multiple lines in C.
    > >
    > > For example :
    > >
    > > int this_is_a_very_long_variable_name = 10;
    > >
    > > I would like to split the "this_is_a_very_long_variable_name " into 2
    > > lines - lets say "this_is_a_" in the first line and
    > > "very_long_variable_name " in the second line.
    > >
    > > Is this possible syntactically in C?
    > >
    > > I tried using the backslash operator in vain :
    > >
    > > int this_is_a_\
    > > very_long_variable_name = 10;
    > >
    > > The above gives a compilation error.

    >
    > int this_is_a_\
    > very_long_variable_name
    >
    > No indentation is permitted when you are attempting to split a token in
    > the middle, since \ does not eat any whitespace other than the
    > immediately following newline.


    Yes, that worked. Thanks for the help. I was actually trying to limit
    the number of characters per line of the source code to 80, for the
    sake of better readability.

    -Sriram.
     
    Sriram Rajagopalan, Nov 13, 2006
    #5
  6. Sriram Rajagopalan

    Chris Dollin Guest

    Chris Dollin wrote:

    > Sriram Rajagopalan wrote:
    >
    >> I was interested to know if there is a way to use a variable name split
    >> across multiple lines in C.

    >
    > There isn't.


    Apparently I'm wrong, since it appears you can use the preprocessor \
    to do this.

    Those with egg may throw now.

    > I'm curious as to what you're doing that needs this.


    That, however, I'll stand by.

    --
    Chris "hantwig efferko VOOM!" Dollin
    "Life is full of mysteries. Consider this one of them." Sinclair, /Babylon 5/
     
    Chris Dollin, Nov 13, 2006
    #6
  7. Chris Dollin said:

    > Sriram Rajagopalan wrote:
    >
    >> I was interested to know if there is a way to use a variable name split
    >> across multiple lines in C.

    >
    > There isn't.


    int are_\
    you_\
    sure_\
    about_\
    that = 42;

    > I'm curious as to what you're doing that needs this.


    Curiosity, perhaps.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: normal service will be restored as soon as possible. Please do not
    adjust your email clients.
     
    Richard Heathfield, Nov 13, 2006
    #7
  8. Sriram Rajagopalan said:

    > I was actually trying to limit
    > the number of characters per line of the source code to 80, for the
    > sake of better readability.


    A better way to do that is to observe the convention of defining just one
    object per line:

    long this = 0;
    long that = 42;
    long the_other = 128;
    long how_long_would_you_like_to_wait_today = 640000L; /* [1] */

    ....and to remember that C only guarantees 31 characters (IIRC) to be
    significant in any internal identifier or macro name, and 6 in any external
    identifier (the latter being raised to 31 in C99).

    If you follow both these suggestions, you won't need to split identifier
    names across line boundaries to meet your 80-column constraint.



    [1] That should be long enough for anybody...

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: normal service will be restored as soon as possible. Please do not
    adjust your email clients.
     
    Richard Heathfield, Nov 13, 2006
    #8
  9. Sriram Rajagopalan wrote:
    > Random832 wrote:
    >> 2006-11-13 <>,
    >> Sriram Rajagopalan wrote:
    >>> Hi,
    >>>
    >>> I was interested to know if there is a way to use a variable name split
    >>> across multiple lines in C.
    >>>
    >>> For example :
    >>>
    >>> int this_is_a_very_long_variable_name = 10;
    >>>
    >>> I would like to split the "this_is_a_very_long_variable_name " into 2
    >>> lines - lets say "this_is_a_" in the first line and
    >>> "very_long_variable_name " in the second line.
    >>>
    >>> Is this possible syntactically in C?
    >>>
    >>> I tried using the backslash operator in vain :
    >>>
    >>> int this_is_a_\
    >>> very_long_variable_name = 10;
    >>>
    >>> The above gives a compilation error.

    >> int this_is_a_\
    >> very_long_variable_name
    >>
    >> No indentation is permitted when you are attempting to split a token in
    >> the middle, since \ does not eat any whitespace other than the
    >> immediately following newline.

    >
    > Yes, that worked. Thanks for the help. I was actually trying to limit
    > the number of characters per line of the source code to 80, for the
    > sake of better readability.
    >

    Use better names for your variables.

    I know this is touching on Holy War territory, but most variables can be
    quite clear and understandable while using only 5-8 characters. Many
    can be one or two characters only. For those important, first-class
    variables, simply make them camel case for readability.

    int count; /* count of something in context */
    int i,j; /* iterators, who cares what they are called */
    char *tmp; /* local temp holder variable */
    char **mailboxNames;
    char *mailboxName;

    A lot of this is simply style, and adhering to a sensible local style at
    your shop is a Good Thing. However, I can see no reason at all for
    something like:

    char **list_of_validated_smtp_mailbox_names;

    Such names are silly, and I would reject such changes if I were
    reviewing your code. Similarly, I would reject out-of-hand code that
    looked this:

    char **complete_validated_SMTP_mailbox_names_use_for_recipient_\
    list_on_the_server_messages;

    The gods created inline comments for a reason! Use them.
     
    Clever Monkey, Nov 13, 2006
    #9
  10. Hey mister,

    Here is another nice research project for you:

    What's the maximum length for a variable name ?!!!!!!!

    I WANT ANSWERS

    So I can compare with Delphi and nag if Delphi is less good than C at this
    specific topic =D

    Cross-post ADDED :p* ;) ! =D

    P.S.:

    I know Delphi has a variable name length limit...

    I forgot what it was though... maybe 128, or 256 or something.

    And if you start nagging to me about this cross post then I say:

    Oh **** you you bastards hahahahahaha.

    Bye,
    Skybuck.
     
    Skybuck Flying, Nov 13, 2006
    #10
  11. Yeah,

    And don't be fooled about this question cause there is a purpose behind it.

    Just the other day I wondered what it takes to crash internet explorer just
    based on legal content.

    For example my bet is that a HTML page of 2 GB + 1 byte will crash internet
    explorer.

    My secondary bet is 4 GB + 1 byte.

    If internet explorer (32 bit version) would not crash then I would be
    amazed.

    Same goes for C compilers in general.

    Are C compilers smart like Delphi by implementing a LIMIT to prevent stupid
    crashes.

    OR are C compilers DUMB as usual... but not implementing any necessary
    limitations :D

    Bye,
    Skybuck =D

    Wieeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

    Usefull trolling makes me feel good tutututututututututututututut-tutut. :D

    Who you gonna call !? :p*
     
    Skybuck Flying, Nov 13, 2006
    #11
  12. Sriram Rajagopalan

    Ben Pfaff Guest

    "Sriram Rajagopalan" <> writes:

    > Random832 wrote:
    >> 2006-11-13 <>,
    >> Sriram Rajagopalan wrote:
    >> > int this_is_a_\
    >> > very_long_variable_name = 10;
    >> >
    >> > The above gives a compilation error.

    >>
    >> int this_is_a_\
    >> very_long_variable_name
    >>
    >> No indentation is permitted when you are attempting to split a token in
    >> the middle, since \ does not eat any whitespace other than the
    >> immediately following newline.

    >
    > Yes, that worked. Thanks for the help. I was actually trying to limit
    > the number of characters per line of the source code to 80, for the
    > sake of better readability.


    I can guarantee that breaking lines at 80 columns with a
    backslash will not aid readability.
    --
    "This is a wonderful answer.
    It's off-topic, it's incorrect, and it doesn't answer the question."
    --Richard Heathfield
     
    Ben Pfaff, Nov 13, 2006
    #12
  13. Sriram Rajagopalan

    Simon Biber Guest

    Richard Heathfield wrote:
    > long how_long_would_you_like_to_wait_today = 640000L; /* [1] */
    >
    > [1] That should be long enough for anybody...


    Shouldn't that be 655360L?

    --
    Simon.
     
    Simon Biber, Nov 13, 2006
    #13
  14. Sriram Rajagopalan

    Ian Collins Guest

    Clever Monkey wrote:
    >
    > The gods created inline comments for a reason! Use them.


    I for one subscribe to the counter argument of "if a block of code
    requires a comment, extract it to a function". Which tends to go hand
    in hand with "if a function name is to long, it's doing too much" :)

    --
    Ian Collins.
     
    Ian Collins, Nov 13, 2006
    #14
  15. Sriram Rajagopalan

    Random832 Guest

    2006-11-13 <>,
    Ian Collins wrote:
    > Clever Monkey wrote:
    >>
    >> The gods created inline comments for a reason! Use them.

    >
    > I for one subscribe to the counter argument of "if a block of code
    > requires a comment, extract it to a function".


    And, the corollary: If a statement or expression requires multiple
    comments, you should really be using some temporaries.

    > Which tends to go hand
    > in hand with "if a function name is to long, it's doing too much" :)
    >
     
    Random832, Nov 13, 2006
    #15
  16. Simon Biber said:

    > Richard Heathfield wrote:
    >> long how_long_would_you_like_to_wait_today = 640000L; /* [1] */
    >>
    >> [1] That should be long enough for anybody...

    >
    > Shouldn't that be 655360L?


    Well, it *should* be 0. I want it NOW! :)

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: normal service will be restored as soon as possible. Please do not
    adjust your email clients.
     
    Richard Heathfield, Nov 13, 2006
    #16
  17. >Which tends to go hand
    >in hand with "if a function name is to long, it's doing too much" :)


    I disagree, especially where the function name is required to contain
    the license for the code.
     
    Gordon Burditt, Nov 13, 2006
    #17
  18. Sriram Rajagopalan wrote:
    > I was actually trying to limit
    > the number of characters per line of the source code to 80, for the
    > sake of better readability.


    That's fine, but how long are your type and variable names? If the
    lengths of a type name and a variable name add up to more than 79
    characters, your code is already terminally unreadable. Splitting a
    name across two lines will make it even worse.
     
    J. J. Farrell, Nov 14, 2006
    #18
  19. J. J. Farrell wrote:
    > Sriram Rajagopalan wrote:
    > > I was actually trying to limit
    > > the number of characters per line of the source code to 80, for the
    > > sake of better readability.

    >
    > That's fine, but how long are your type and variable names? If the
    > lengths of a type name and a variable name add up to more than 79
    > characters, your code is already terminally unreadable. Splitting a
    > name across two lines will make it even worse.


    Lets say that the variable name is quite small and due to multiple
    nested if-else and a 4 space indentation per if-else, I end up in a
    situation where I wud have to split my variable name?
     
    Sriram Rajagopalan, Nov 14, 2006
    #19
  20. Sriram Rajagopalan

    Richard Bos Guest

    "Sriram Rajagopalan" <> wrote:

    > J. J. Farrell wrote:
    > > Sriram Rajagopalan wrote:
    > > > I was actually trying to limit
    > > > the number of characters per line of the source code to 80, for the
    > > > sake of better readability.

    > >
    > > That's fine, but how long are your type and variable names? If the
    > > lengths of a type name and a variable name add up to more than 79
    > > characters, your code is already terminally unreadable. Splitting a
    > > name across two lines will make it even worse.

    >
    > Lets say that the variable name is quite small and due to multiple
    > nested if-else and a 4 space indentation per if-else, I end up in a
    > situation where I wud have to split my variable name?


    Then you need to nest your if-elses a lot less deep. You'd need about a
    dozen to get to that situation, and you shouldn't. Not for the language,
    or the compiler; they'll have no problems with it whatsoever. But for
    the programmer who will have to maintain this program a year from now,
    it'll be a nightmare - even if that maintenance programmer is you.

    Richard
     
    Richard Bos, Nov 14, 2006
    #20
    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. pbd22
    Replies:
    0
    Views:
    298
    pbd22
    Nov 18, 2007
  2. Mark
    Replies:
    4
    Views:
    1,233
    Hermann Peifer
    Mar 27, 2009
  3. Jamie Jackson

    Spanning Lines & Dynamic Pattern Matching

    Jamie Jackson, Oct 25, 2004, in forum: Javascript
    Replies:
    5
    Views:
    114
    Jamie Jackson
    Oct 26, 2004
  4. Voitec
    Replies:
    9
    Views:
    247
    Iain Chalmers
    Nov 13, 2003
  5. animesh
    Replies:
    0
    Views:
    86
    animesh
    Dec 10, 2007
Loading...

Share This Page