views:

236

answers:

4

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?

A: 

Visual Studio is invoking the linker LINK.exe it works primarily with object files as input, to produce an executable as output, but also is capable of much other work concerning these and related files. Linker Command-Line Syntax @ MSDN

Nadir SOUALEM
I don't think so in this case, meds is referring to compilation of source, not link time. Although you are correct in that the linker can also generate code for instantiating templates.
Steve Folly
+1  A: 

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.

sbi
I suppose that, whoever down-voted this, knows better. Care to enlighten me?
sbi
A: 

Template instances (and other type of code) might generate code (or not in some conditions).

Klaim
Yes, but VC does take its time for this phase even when there are no templates in the code.
sbi
+1  A: 

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" :)

AndreyT