Results 1 to 5 of 5

Thread: compiler (lack of) optimization

  1. #1

    Thread Starter
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048

    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?

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    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.

  3. #3

    Thread Starter
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048

    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.

  4. #4
    Junior Member
    Join Date
    Nov 2008
    Posts
    25

    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.

  5. #5
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    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
  •  



Click Here to Expand Forum to Full Width