www.digitalmars.com         C & C++   DMDScript  

c++ - DMC on large source files

reply Michael <no spam.com> writes:
When trying to compile large (approx. 2.2mb) source file I'm getting
following error:

nbytes = 65600, ph_maxsize = 65520
Internal error: ph 1848
--- errorlevel 1

In c++ beta forum one said its due to macro expansion buffer
overflow. Is there any way to tell dmc to use larger buffer or any
other way around this problem?
Oct 10 2007
next sibling parent reply chris elliott <biol75 york.ac.uk> writes:
did you set -HP in your dmc command line?
http://www.digitalmars.com/ctg/sc.html#dashCapHCapP

Michael wrote:
 When trying to compile large (approx. 2.2mb) source file I'm getting
 following error:
 
 nbytes = 65600, ph_maxsize = 65520
 Internal error: ph 1848
 --- errorlevel 1
 
 In c++ beta forum one said its due to macro expansion buffer
 overflow. Is there any way to tell dmc to use larger buffer or any
 other way around this problem?
Oct 10 2007
parent Michael <no spam.com> writes:
== Quote from chris elliott (biol75 york.ac.uk)'s article
 did you set -HP in your dmc command line?
 http://www.digitalmars.com/ctg/sc.html#dashCapHCapP
Yes I tried values from 50 to 1000, same error though.
Oct 10 2007
prev sibling parent reply Walter Bright <newshound1 digitalmars.com> writes:
Michael wrote:
 When trying to compile large (approx. 2.2mb) source file I'm getting
 following error:
 
 nbytes = 65600, ph_maxsize = 65520
 Internal error: ph 1848
 --- errorlevel 1
 
 In c++ beta forum one said its due to macro expansion buffer
 overflow. Is there any way to tell dmc to use larger buffer or any
 other way around this problem?
This can happen also if you have an unterminated string, and the compiler tries to read in your whole source file into one string. I'd try the 'divide-and-conquer' approach. Divide the source file in half, and see which side generates the error. Rinse, repeat.
Oct 10 2007
next sibling parent reply Michael <no spam.com> writes:
This happens because of huge switch statement.
Huge means number of 'case' statements over 4050.
Smallest test case can be produced using following ruby script:
=== cut ===
print "int main() {\n"
print "\tint i = 0;\n"
print "\tswitch(i) {\n"

1.upto(ARGV[0].to_i) do |x|

end

print "\t}\n"
print "dummy:\n"
print "\treturn 0;\n"
print "}"
=== cut ===
Everything else in that huge file compiles fine. Anything can be done
about it?
Oct 10 2007
parent reply Walter Bright <newshound1 digitalmars.com> writes:
Michael wrote:
 This happens because of huge switch statement.
 Huge means number of 'case' statements over 4050.
 Smallest test case can be produced using following ruby script:
 === cut ===
 print "int main() {\n"
 print "\tint i = 0;\n"
 print "\tswitch(i) {\n"
 
 1.upto(ARGV[0].to_i) do |x|

 end
 
 print "\t}\n"
 print "dummy:\n"
 print "\treturn 0;\n"
 print "}"
 === cut ===
 Everything else in that huge file compiles fine. Anything can be done
 about it?
Try splitting the case statement into two: switch (i) { case 1: case 2: ... default: switch (i) { case 1000: case 1001: ... } }
Oct 11 2007
parent reply DQNOK <davidlqualls yahoo.com> writes:
== Quote from Walter Bright (newshound1 digitalmars.com)'s article
 Michael wrote:
 This happens because of huge switch statement.
 Huge means number of 'case' statements over 4050.
What does the compiler do with case statements? I was told as a youth to use them instead of if elseif elseif ... else constructs because they were more efficient. Then I disassembled one (of my old) compiler's output and saw that it just tested each case sequentially; just like the if else construct. On that (single) basis, I've usually veered toward using arrays of functions instead of case statements. Instead of switch( i ) { case 0: do0thing; case 1: do1thing; case 2: do2thing; } I write: do_n_thing[i](); Is it customary nowadays in good compilers to transform switch statements into a set of internal jmps, or do they check thru every case sequentially? How should one deal with 4000 cases? David
Oct 16 2007
parent Walter Bright <newshound1 digitalmars.com> writes:
DQNOK wrote:
 Is it customary nowadays in good compilers to transform switch
 statements into a set of internal jmps, or do they check thru
 every case sequentially?  How should one deal with 4000 cases?
Compilers use different strategies depending on the number and density of the cases.
Oct 16 2007
prev sibling parent Heinz Saathoff <newshsaat arcor.de> writes:
Hello,

Walter Bright wrote...
 In c++ beta forum one said its due to macro expansion buffer
 overflow. Is there any way to tell dmc to use larger buffer or any
 other way around this problem?
This can happen also if you have an unterminated string, and the compiler tries to read in your whole source file into one string.
But only if the source is one long line. Otherwise the compiler will give the error Lexical error: unterminated string - Heinz
Oct 16 2007