Syntax for variable names spanning multiple lines in C

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sriram Rajagopalan

    Syntax for variable names spanning multiple lines in C

    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_n ame = 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_vari able_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_varia ble_name = 10;

    The above gives a compilation error.

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

    Thanks,
    Sriram.

  • Chris Dollin

    #2
    Re: Syntax for variable names spanning multiple lines in C

    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/

    Comment

    • loic-dev@gmx.net

      #3
      Re: Syntax for variable names spanning multiple lines in C

      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_n ame = 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_vari able_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_varia ble_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_varia ble_name = 10;

      HTH,
      Loic.

      Comment

      • Random832

        #4
        Re: Syntax for variable names spanning multiple lines in C

        2006-11-13 <1163427607.170 877.270750@b28g 2000cwb.googleg roups.com>,
        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_n ame = 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_vari able_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_varia ble_name = 10;
        >
        The above gives a compilation error.
        int this_is_a_\
        very_long_varia ble_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.

        Comment

        • Sriram Rajagopalan

          #5
          Re: Syntax for variable names spanning multiple lines in C


          Random832 wrote:
          2006-11-13 <1163427607.170 877.270750@b28g 2000cwb.googleg roups.com>,
          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_n ame = 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_vari able_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_varia ble_name = 10;

          The above gives a compilation error.
          >
          int this_is_a_\
          very_long_varia ble_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.

          Comment

          • Chris Dollin

            #6
            Re: Syntax for variable names spanning multiple lines in C

            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/

            Comment

            • Richard Heathfield

              #7
              Re: Syntax for variable names spanning multiple lines in C

              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

              email: normal service will be restored as soon as possible. Please do not
              adjust your email clients.

              Comment

              • Richard Heathfield

                #8
                Re: Syntax for variable names spanning multiple lines in C

                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_wai t_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

                email: normal service will be restored as soon as possible. Please do not
                adjust your email clients.

                Comment

                • Clever Monkey

                  #9
                  Re: Syntax for variable names spanning multiple lines in C

                  Sriram Rajagopalan wrote:
                  Random832 wrote:
                  >2006-11-13 <1163427607.170 877.270750@b28g 2000cwb.googleg roups.com>,
                  >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_n ame = 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_va riable_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_varia ble_name = 10;
                  >>>
                  >>The above gives a compilation error.
                  >int this_is_a_\
                  >very_long_vari able_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_valid ated_smtp_mailb ox_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_vali dated_SMTP_mail box_names_use_f or_recipient_\
                  list_on_the_ser ver_messages;

                  The gods created inline comments for a reason! Use them.

                  Comment

                  • Skybuck Flying

                    #10
                    Re: Syntax for variable names spanning multiple lines in C

                    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 fuck you you bastards hahahahahaha.

                    Bye,
                    Skybuck.


                    Comment

                    • Skybuck Flying

                      #11
                      Re: Syntax for variable names spanning multiple lines in C

                      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

                      Wieeeeeeeeeeeee eeeeeeeeeeeeeee eeeeeeeeeeeeeee eeeeeeeeeeeeeee eeeee

                      Usefull trolling makes me feel good tututututututut ututututututut-tutut. :D

                      Who you gonna call !? :P*


                      Comment

                      • Ben Pfaff

                        #12
                        Re: Syntax for variable names spanning multiple lines in C

                        "Sriram Rajagopalan" <bglsriram@gmai l.comwrites:
                        Random832 wrote:
                        >2006-11-13 <1163427607.170 877.270750@b28g 2000cwb.googleg roups.com>,
                        >Sriram Rajagopalan wrote:
                        int this_is_a_\
                        very_long_varia ble_name = 10;
                        >
                        The above gives a compilation error.
                        >>
                        >int this_is_a_\
                        >very_long_vari able_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

                        Comment

                        • Simon Biber

                          #13
                          Re: Syntax for variable names spanning multiple lines in C

                          Richard Heathfield wrote:
                          long how_long_would_ you_like_to_wai t_today = 640000L; /* [1] */
                          >
                          [1] That should be long enough for anybody...
                          Shouldn't that be 655360L?

                          --
                          Simon.

                          Comment

                          • Ian Collins

                            #14
                            Re: Syntax for variable names spanning multiple lines in C

                            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.

                            Comment

                            • Random832

                              #15
                              Re: Syntax for variable names spanning multiple lines in C

                              2006-11-13 <4rs5guFrsdaoU1 3@mid.individua l.net>,
                              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" :)
                              >

                              Comment

                              Working...