On Sat, 2023-10-21 at 16:10 +0200, Kai Song via Gcc-help wrote: > I understand (and needless to say couldn't do it better) that it may > just be for now a too difficult problem to actually compile lengthy > cpp. I just want to be very clear here. When you say "lengthy cpp" that is not very precise because "cpp" is not an accurate term. What is true is the the compiler will have problems compiling extremely long SINGLE FUNCTIONS. It doesn't really matter how long the source file is (how many functions it contains). What matters is now large each function is. In order to make your generated code digestible for compilers, you need to break up your algorithms into multiple smaller functions. > The question that I was targeting at is: What can I realistically do > (implying that refactoring in the remaining project's period appears > nonviable)? Of course we cannot decide what is realistic or not. Your comments here seem to imply that you would be wiling to rewrite the entire thing to generate output in a completely different language so it seems you are willing and able to make very sweeping changes. It's hard for us to understand why you can't extract parts of your generated code and put them into separate functions. Surely you must have loops in your code: can't the body of some of these loops become separate functions? If there are steps to the algorithm can't each of these steps become a separate function? You can collect all the state of the algorithm into one large global structure, rather than having individual local variables, and all the functions can refer to that global state structure, so you don't have to pass the data around as arguments. > Are there languages with similar capabilities to cpp that I could > generate into equivalently and that are as easy to learn Since we don't know which particular capabilities of C++ you are relying on that's difficult to say. However, my feeling is that no matter what language you use you will run into these limitations: compilers in general simply are not written to have single functions which are hundreds of thousands of lines long. Functions help humans organize their thinking and programming, but they also are critical for compilers to make their jobs simpler (or even possible). Rather than learning a new language, I think you should be revisiting your code generation and attempting to understand how to break it up. I don't think there's any feasible alternative.