maximum length of a statement

Oct 23, 2012 at 6:39am
Hi.
Is there anything like the maximum length of a statement in C?
Oct 23, 2012 at 6:54am
From the compiler's point of view? Probably heaps - like 1024 chars or even more.

From a practical point of view? 80 chars - this is so one doesn't have to scroll sideways all the time ( which is rather irritating). Also if someone wants to print the code, then this is better.
Oct 23, 2012 at 7:09am
so it''s not 255 characters?

Please give me a source which states that
Last edited on Oct 23, 2012 at 7:10am
Oct 23, 2012 at 7:18am
I found the answer - with my best tool - Google

Google this:

C maximum statement length

Now how hard was that?

Having found the answer, I think that my original answer is more important.

Do you have a compiler error? If so, there is probably a much bigger problem.
Oct 23, 2012 at 8:17am
I can't see why there should be a maximum length. Surely the source code tokeniser just sees a stream of text.
Oct 23, 2012 at 8:39am
I don't have a compiler error.A test has an option reading this way.
Oct 23, 2012 at 8:52am
1
2
3
4
5
6
7
8
9
10
11
I found the answer - with my best tool - Google

Google this:

C maximum statement length

Now how hard was that?

Having found the answer, I think that my original answer is more important.

Do you have a compiler error? If so, there is probably a much bigger problem. 

I have googled that and got no real answer, so I started the thread.

Oct 23, 2012 at 11:28am
The answer is no. There's no limit for a c statement. A new line is only an optical effect (except for macros) but does not end a c statement.
Oct 23, 2012 at 11:38am
http://stackoverflow.com/questions/11614687/maximum-length-of-statement-in-c


This was the web site I found, it talks about a limit of 4095 from the C++ standard . Obviously not C, but as far as that goes, it's a reasonable answer.


I wonder why the length of a statement is a problem?
Oct 23, 2012 at 11:49am
They're talking about a particular compiler (gcc) and string literals. But I don't think that such a limit exists because a picture format (XPM) consists of strings...
Oct 23, 2012 at 11:58am
@hooshdar3
A test has an option reading this way.


Wondering what you mean?
Oct 23, 2012 at 12:20pm
From the C Standard

5.2.4.1 Translation limits
1 The implementation shall be able to translate and execute at least one
program that contains at least one instance of every one of the following limits
....
— 4095 characters in a logical source line


From the C++ Standard

Annex B (informative)
Implementation quantities [implimits]
1 Because computers are finite, C++ implementations are inevitably limited in
the size of the programs they can successfully process. Every implementation
shall document those limitations where known. This documentation may cite
fixed limits where they exist, say how to compute variable limits as a function
of available resources, or say that fixed limits do not exist or are unknown.

2 The limits may constrain quantities that include those described below or
others. The bracketed number following each quantity is recommended as the
minimum for that quantity. However, these quantities are only guidelines and
do not determine compliance.


— Characters in one logical source line [65 536].


So in C++ you can write a program horizontally in one long line.:)
Last edited on Oct 23, 2012 at 12:31pm
Topic archived. No new replies allowed.