Syntax for variable names spanning multiple lines in C

S

Sriram Rajagopalan

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.
 
C

Chris Dollin

Sriram said:
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.
 
L

loic-dev

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.
 
R

Random832

2006-11-13 said:
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.
 
S

Sriram Rajagopalan

Random832 said:
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.
 
R

Richard Heathfield

Chris Dollin said:
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.
 
R

Richard Heathfield

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.
 
C

Clever Monkey

Sriram said:
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.
 
S

Skybuck Flying

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.
 
S

Skybuck Flying

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*
 
B

Ben Pfaff

Sriram Rajagopalan said:
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.
 
I

Ian Collins

Clever said:
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" :)
 
R

Random832

2006-11-13 said:
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.
 
R

Richard Heathfield

Simon Biber said:
Richard said:
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.
 
G

Gordon Burditt

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.
 
J

J. J. Farrell

Sriram 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.

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.
 
S

Sriram Rajagopalan

J. J. Farrell said:
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?
 
R

Richard Bos

Sriram Rajagopalan said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top