Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Syntax for variable names spanning multiple lines in C

Reply
Thread Tools

Syntax for variable names spanning multiple lines in C

 
 
Sriram Rajagopalan
Guest
Posts: n/a
 
      11-13-2006
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.

 
Reply With Quote
 
 
 
 
Chris Dollin
Guest
Posts: n/a
 
      11-13-2006
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/

 
Reply With Quote
 
 
 
 
loic-dev@gmx.net
Guest
Posts: n/a
 
      11-13-2006
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.

 
Reply With Quote
 
Random832
Guest
Posts: n/a
 
      11-13-2006
2006-11-13 <(E-Mail Removed) .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_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.
 
Reply With Quote
 
Sriram Rajagopalan
Guest
Posts: n/a
 
      11-13-2006

Random832 wrote:
> 2006-11-13 <(E-Mail Removed) .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_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.

 
Reply With Quote
 
Chris Dollin
Guest
Posts: n/a
 
      11-13-2006
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/

 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      11-13-2006
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.
 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      11-13-2006
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.
 
Reply With Quote
 
Clever Monkey
Guest
Posts: n/a
 
      11-13-2006
Sriram Rajagopalan wrote:
> Random832 wrote:
>> 2006-11-13 <(E-Mail Removed) .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_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_re cipient_\
list_on_the_server_messages;

The gods created inline comments for a reason! Use them.
 
Reply With Quote
 
Skybuck Flying
Guest
Posts: n/a
 
      11-13-2006
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 * ! =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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
empty xml element spanning multiple lines Mark XML 4 03-27-2009 11:05 AM
How to filter out lines from a variable that has multi-lines? mike Perl Misc 3 10-02-2007 12:08 AM
Spanning Lines & Dynamic Pattern Matching Jamie Jackson Javascript 5 10-26-2004 01:26 PM
print statement spanning multiple lines Voitec Perl Misc 9 11-13-2003 02:03 AM
Spanning Tree And Per Vlan Spanning Tree Amy L. Cisco 0 07-24-2003 10:01 PM



Advertisments