By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,340 Members | 1,988 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,340 IT Pros & Developers. It's quick & easy.

Syntax for variable names spanning multiple lines in C

P: n/a
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.

Nov 13 '06 #1
Share this Question
Share on Google+
28 Replies


P: n/a
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/

Nov 13 '06 #2

P: n/a
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 '06 #3

P: n/a
2006-11-13 <11**********************@b28g2000cwb.googlegroups .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.
Nov 13 '06 #4

P: n/a

Random832 wrote:
2006-11-13 <11**********************@b28g2000cwb.googlegroups .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.

Nov 13 '06 #5

P: n/a
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/

Nov 13 '06 #6

P: n/a
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.
Nov 13 '06 #7

P: n/a
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.
Nov 13 '06 #8

P: n/a
Sriram Rajagopalan wrote:
Random832 wrote:
>2006-11-13 <11**********************@b28g2000cwb.googlegroups .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.
Nov 13 '06 #9

P: n/a
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.
Nov 13 '06 #10

P: n/a
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

Wieeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee eeeeeeeeeeeeeee

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

Who you gonna call !? :P*
Nov 13 '06 #11

P: n/a
"Sriram Rajagopalan" <bg*******@gmail.comwrites:
Random832 wrote:
>2006-11-13 <11**********************@b28g2000cwb.googlegroups .com>,
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
Nov 13 '06 #12

P: n/a
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.
Nov 13 '06 #13

P: n/a
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.
Nov 13 '06 #14

P: n/a
2006-11-13 <4r*************@mid.individual.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" :)
Nov 13 '06 #15

P: n/a
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.
Nov 13 '06 #16

P: n/a
>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.
Nov 13 '06 #17

P: n/a

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.

Nov 14 '06 #18

P: n/a

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?

Nov 14 '06 #19

P: n/a
"Sriram Rajagopalan" <bg*******@gmail.comwrote:
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
Nov 14 '06 #20

P: n/a
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?
Two solutions:

Use 2 space indents.

Don't nest too deep, extract functions.

Failing that, split expressions, not variable names. Once you split a
variable name, you loose your indentation.

--
Ian Collins.
Nov 14 '06 #21

P: n/a
Sriram Rajagopalan wrote:

<snip>
int this_is_a_\
very_long_variable_name = 10;

The above gives a compilation error.
Good, after translation phase 2, this appear as

int this_is_a_ very_long_variable_name = 10;
Please suggest the means to do this if there is any.
This is a horrible idea, don't do it!

Having very long identifiers is a bad idea. First of all, identifiers
with external linkage may have only 6 significant initial characters
(C90). Even the internal identifiers in C99, may have no more than 63
significant initial characters. So, you are begging for bugs.. !

Second, readability, splitting identifiers on multiple lines, will not
increase the readability of your code, it will only tell others that
the code was written by a clueless person.

There are cases, where I have generated identifiers, not by use of line
splicing, but rather via the ## operator:

#define make_ident(a, b) a ## b

--
Tor <torust AT online DOT no>

Nov 14 '06 #22

P: n/a


Sriram Rajagopalan wrote On 11/14/06 02:35,:
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?
if (a)
if (b)
if (c)
if (d)
if (e)
if (f)
if (g)
if (h)
if (i)
if (j)
if (k)
if (l)
if (m)
x = va1\
ue;
else
dx = va\
lue;

IMHO, the code is already unreadable and its readability
is not salvaged by splitting an identifier and forcing the
reader's eye to make a saccade. Did you spot the error in
the above on your first reading of it?

--
Er*********@sun.com

Nov 14 '06 #23

P: n/a
In article <1163515741.512677@news1nwk>,
Eric Sosman <Er*********@sun.comwrote:
....
IMHO, the code is already unreadable and its readability
is not salvaged by splitting an identifier and forcing the
reader's eye to make a saccade. Did you spot the error in
the above on your first reading of it?
It looks fine to me, assuming, of course, that you have properly
declared and initialized variables: a,b,c,d,e,f,g,h,i,j,k,l,m,x,value,
and va1ue.

You do, don't you?

Nov 14 '06 #24

P: n/a
Kenny McCormack wrote:
In article <1163515741.512677@news1nwk>,
Eric Sosman <Er*********@sun.comwrote:
...
IMHO, the code is already unreadable and its readability
is not salvaged by splitting an identifier and forcing the
reader's eye to make a saccade. Did you spot the error in
the above on your first reading of it?

It looks fine to me, assuming, of course, that you have properly
declared and initialized variables: a,b,c,d,e,f,g,h,i,j,k,l,m,x,value,
and va1ue.
Missing parenthesis.

Nov 14 '06 #25

P: n/a
In article <11**********************@f16g2000cwb.googlegroups .com>,
santosh <sa*********@gmail.comwrote:
>Kenny McCormack wrote:
>In article <1163515741.512677@news1nwk>,
Eric Sosman <Er*********@sun.comwrote:
...
IMHO, the code is already unreadable and its readability
is not salvaged by splitting an identifier and forcing the
reader's eye to make a saccade. Did you spot the error in
the above on your first reading of it?

It looks fine to me, assuming, of course, that you have properly
declared and initialized variables: a,b,c,d,e,f,g,h,i,j,k,l,m,x,value,
and va1ue.

Missing parenthesis.
Where?

Nov 14 '06 #26

P: n/a
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 would aggravate me more than a long line, for reasons not the least
of which is the 240 column xterm I get on the big monitor at the office,
or the 160 columns I get even with a big font here on my portable box...

Anyway, I think it would be much better if you just introduced a new
variable, assigned to it the value your long variable, and used that in
the routine. Or, if you refrained from using overly long identifiers to
begin with would be best, since presumably, readability is your goal.
Better to just explain what you're doing in a comment.
Nov 14 '06 #27

P: n/a
2006-11-14 <EI*******************@newsfe07.phx>,
james of tucson 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 would aggravate me more than a long line, for reasons not the least
of which is the 240 column xterm I get on the big monitor at the office,
Wouldn't it be better to have 3 80-column xterms?
Nov 14 '06 #28

P: n/a
Eric Sosman <Er*********@sun.comwrote:
Sriram Rajagopalan wrote On 11/14/06 02:35,:
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?

if (a)
if (b)
if (c)
if (d)
if (e)
if (f)
if (g)
if (h)
if (i)
if (j)
if (k)
if (l)
if (m)
x = va1\
ue;
else
dx = va\
lue;

IMHO, the code is already unreadable and its readability
is not salvaged by splitting an identifier and forcing the
reader's eye to make a saccade. Did you spot the error in
the above on your first reading of it?
While I agree with your point, IMO your illustration is flawed. I
wouldn't have spotted that error in my newsreader whether the nesting
was reasonable or not. It's a defect in the font I use. In my editor, I
use a different font, and I'd have a much better chance of spotting it.

Richard
Nov 16 '06 #29

This discussion thread is closed

Replies have been disabled for this discussion.