Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VC++ 'Generating Code', what does it mean?

WHen compiling in visual studio the compiler outputs this at what seems to be its own discretion:

1>Generating Code...

what is it doing here exactly?

like image 514
meds Avatar asked Nov 22 '09 11:11

meds


People also ask

What is Link Time Code Generation?

Link-time code generation (LTCG) enables cross source-file optimization by delaying code generation until the link stage. This can significantly reduce code size. To enable LTCG, compile your source with -c --ltcg to create objects in an intermediate format.

How do I run a CPP file in Visual Studio?

Build and run your code in Visual Studio To build your project, choose Build Solution from the Build menu. The Output window shows the results of the build process. To run the code, on the menu bar, choose Debug, Start without debugging. A console window opens and then runs your app.


2 Answers

It is doing what it says: it is generating the machine code. Many compilers translate C/C++ sources into some intermediate internal representation that is later used as the source to generate the actual machine code. Visual C++ compiler (as many other compilers) does this in batches: first it translates a bunch of source files into that intermediate representation and then converts them all to machine code (and then starts working on the next batch). This is what happens when you see the "Generating code" messages.

I don't know what logic exactly it is using to split the source files into batches. Maybe it works simply by size: once the total size of all intermediate representations generated so far gets to some limit, it switches to "generating code" mode. Maybe there's some other logic at work there as well.

In any case note that the unqualified term "code" in this case does not refer to source code, meaning that it has nothing to do with templates and/or preprocessor or anything like that. Moreover, referring to C sources with unqualified "code" (as opposed to the qualified "source code") is a very niche thing, more at home with marketing department than with actual programmers. At the programmers' level nobody refers to C sources as just "code" :)

like image 134
AnT Avatar answered Sep 22 '22 02:09

AnT


The compiler is given multiple input files at once and it reads (parses) several of those in one go, and only then produces output (object files) for them, before it reads more input files. I suppose this is an optimization, presumably because mixed read/write access to the disk is slower than when it is sorted into (first) read access and (then) write access.

like image 35
sbi Avatar answered Sep 21 '22 02:09

sbi