How long can a line of code be?

This is just out of curiosity! Does anyone know what is the maximum number of characters that a line of code can have?

EDIT: Added more details.

Is it possibly possible to make two lines become one? .... This seems pretty odd, I dont know how to explain it, but maybe an example would be useful:
Suppose I have the following piece of code
1
2
#define A cout << "Hello,"
  << "world";

It obviously would not be syntactically legal to do something like that.
But, of course #define A cout << "Hello World"; would do! So back to the question, is there any possible way to "connect" two lines of code and make them become one?
Last edited on
As far as I know, the language doesn't define any limit on the length of a line.
As for your second question, a \ at the end of a line tells the compiler to ignore the newline sequence. This has precedence over just about everything:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#inc\
lude <ios\
tream>

/\
/A comment. (May not work everywhere.)
/\
* Another comment (May not work everywhere.) *\
/

in\
t main(){
    std::cout <<"Hello,\
 World!"<<std:\
:endl;
    return 0;
}
Last edited on
This reminds me of this funny gotcha with the trigraphs.. does it still work on today's compilers?

1
2
3
// what the heck is wrong here??????????????/
if (false)
    cout << "not false";


:-D


Ciao, Imi.
I think it should be like this:
1
2
3
// what the heck is wrong here??????????????\
if (false)
    cout << "not false";
So is it the backslash "\" or is it the forward slash "/" ??????
The backslash
By the way, does it work in Java, too? Or is there any equivalent methodology to this in Java?
I think it should be like this:


No, it was correct as I wrote it. It's a forward slash. Notice, that for english keyboards, the forward slash is directly "under" the question mark, so this is not tooo hard to write by accident. Just a slip of the shift key!!!!!1!!! ;-)

1
2
3
// what the heck is wrong here??????????????/
if (false)
    cout << "not false";


The solution is: Trigraphs. When times where old, some keyboards didn't support fancy keys like "\". So C included so called "trigraphs" which are ?? and some key and they get converted into another key. The trigraph for \ is in fact ??/. C++ inherited this, so the end of the line gets converted into a backslash. The trigraph-conversion is the first thing a compiler does even before determining the line structure. (That's makes sense, because back then, people especially wanted to use trigraphs in place of other, untypable characters).

Ah, found the link: http://www.gotw.ca/gotw/086.htm

Ciao, Imi.
So is it the backslash "\" or is it the forward slash "/" ??????


It's the backslash "\" you should use.


My story was just a funny "What's THAT?" - effect from very old times. It most probably won't work anymore (It doesn't under MSVC) and even if it works, its ugly and give warnings and people will hate you and whatever. ;-)

If you should stumble upon some code using ??/ instead of \ at the end of lines, change it to \ ;-)

Ciao, Imi.
Topic archived. No new replies allowed.