#### Archived

This topic is now archived and is closed to further replies.

# How good is the C++Compiler?

This topic is 6930 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Well I have been wondering a bit about, how good/optimized the C++Compiler is. If I write code like:
a = 23 +7;

Will the compiler optimize this code to:
a = 30;

Which is faster and always correct. Also when you write C++ code like:
func()
{
UINT  u1, u2, u3;

// Do something.
UINT  u4, u5;

}


Is the compiler then allocating memory 2 places, or just in the begining of the function. Because if the memory gets allocated one place, there´s a bigger chance, that it will fit into the CPUs cache, which is faster. Hope somebody knows this, because I want fast code! But don´t we all?

##### Share on other sites
Depends on the compiler, but there''s an easy way to find out: compile that code, disassemble, and see what it has generated!

#pragma DWIM // Do What I Mean!
**I use Software Mode**

##### Share on other sites
I could do that, but I don´t know assembler that well.
I can read some of it, but I still have to learn more, before getting skilled enough.

Also the source for a Windows program in assembler is very big , so I can´t find the correct line to look in.
Perhaps there is an easy breakpoint kind-of-way?

So have anyone tried this, and knows the answer to my question?

Edited by - The big Question? on 5/3/00 6:39:16 AM

##### Share on other sites
quote:

If I write code like:
a = 23 +7;

Will the compiler optimize this code to:
a = 30;

Everything I have read suggests that yes, it does optimize. This is one of the reasons #defines are so fast.

Mike

##### Share on other sites
Most optimizing compilers do both of the ones you mention. You can check your compiler manual for a list of the optional optimizations.

Some optimizations, like the ones you mention, are "no brainers" and aren''t even mentioned in the manual, because there''s no chance that they can break "fragile" code.

##### Share on other sites
If you want to see the assembly code for a specific block of instructions, set a breakpoint there and then when you get to the breakpoint, open up the disassambly window to look at the assembler instructions. (Well atleast using msvc++, but I assume other compilers have similar features.)

##### Share on other sites
Thanks to all who helped...
Now I can test the compiler, and hopefully write better optimized code.

Edited by - The big Question? on 5/4/00 5:35:39 PM

##### Share on other sites
> Also the source for a Windows program in assembler is
> very big , so I can´t find the correct line to look in.
> Perhaps there is an easy breakpoint kind-of-way?

There''s another way (I prefer):
- Let the compiler generate a listing file.
- View the listing file and search for FINDTHIS.

*** It''s also possible to include your C source as comment in the listing file.

Hope this helps,
Bas.

##### Share on other sites
quote:

There''s another way (I prefer):
- Let the compiler generate a listing file.
- View the listing file and search for FINDTHIS .

Hi there!
I am pretty sure that I have read somewhere, that the compiler edits out all the comments when compiling, which makes sense, because if if was left there, it would only be a waste of space(in compiled code anyway)...
If the comments were to stay in compiled code, people would be relctant to even include comments in their code, as it would increase the size of thier .exe''s

davior

##### Share on other sites
Big difference between compiling to assembly and compiling to object code. Of course when compiled to object code comments are stripped; however, when compiled to assembly some compilers retain comments. Not to mention sticking in some comments of their own, such as original C source for the assembly block.

And allocating the memory at the beginning of the function isn''t so much an optimization, as it is part of the calling convention.

• 15
• 13
• 35
• 39
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!