-
Feb 19th, 2009, 03:27 PM
#1
Thread Starter
Frenzied Member
compiler (lack of) optimization
i had
Code:
#define DATA_SIZE 65536
and decided to change it to
Code:
#define DATA_SIZE (2^16) // 65536
I thought for sure my compiler would optimize that to a literal constant (65536) but instead it actually stored the instruction to figure out 2^16.. I've reverted back to the first line but was curious as to why it did that. Is it my compiler being 'dumb' or is there something I'm missing?
-
Feb 20th, 2009, 07:58 AM
#2
Re: compiler (lack of) optimization
That's a preprocessor expression. They don't get optimised, it is simply text. It doesn't represent a mathematical expression, rather it just looks like it does.
I don't live here any more.
-
Feb 20th, 2009, 08:57 AM
#3
Thread Starter
Frenzied Member
Re: compiler (lack of) optimization
I realize preprocessor directives are just a text replacement.. however once its in the code, it should then be optimized.
I figured out the correct answer. 2^16 is not 2 to the 16th (65536) its 2 xor 16 (18). My function was taking considerably longer because data was only read 18 bytes at a time.
-
Feb 21st, 2009, 12:11 PM
#4
Junior Member
Re: compiler (lack of) optimization
C++ doesn't know ^ (to the power of)
Don't you need pow(2,16)
Unless you are asking something else.
-
Feb 22nd, 2009, 08:39 AM
#5
Re: compiler (lack of) optimization
or alternatively:
Code:
#define DATA_SIZE (1 << 16) // 65536
which is a constant expression.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|