maximum length of a statement

Hi.
Is there anything like the maximum length of a statement in C?
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.
so it''s not 255 characters?

Please give me a source which states that
Last edited on
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 can't see why there should be a maximum length. Surely the source code tokeniser just sees a stream of text.
I don't have a compiler error.A test has an option reading this way.
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.

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.
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?
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...
@hooshdar3
A test has an option reading this way.


Wondering what you mean?
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
Topic archived. No new replies allowed.