title: Optimization of #define vs static const (in avr-gcc)
body: <p>Although I welcome answers on this on a general scope, I'm asking primarily for avr-gcc to make this not too broad.</p>
  
  <p>I have looked at some questions, particularly <a href="https://stackoverflow.com/questions/1674032/static-const-vs-define-in-c">this</a> and <a href="https://stackoverflow.com/questions/2308194/shall-i-prefer-constants-over-defines/2308364#2308364">this</a> one. They mostly look at semantic differences, e.g. that a <code>static const</code> can't be used in place of a constant expression. However, although talking about memory allocation in general, they don't speak about optimization.</p>
  
  <p>Let's look at an example:</p>
  
  <pre><code>typedef struct {
      GPIO_TypeDef *port;
      uint8_t  pin;
  } gpio_pin_t;
  
  static inline void gpio_pin_set(gpio_pin_t gpio, bool set) {
      if(set) GPIO_SetBits  (gpio.port, 1 &lt;&lt; gpio.pin);
      else    GPIO_ResetBits(gpio.port, 1 &lt;&lt; gpio.pin);
  }
  
  //elsewhere including above definitions
  
  static const gpio_pin_t gpio_pin = {GPIOE, 8};
  
  void some_function(bool enable) {
      gpio_pin_set(gpio_pin, enable);
  }
  </code></pre>
  
  <p>As you can see, I'm using structs, so the third established way (enum) is not an option here</p>
  
  <p>Can I expect gcc to optimize the <code>gpio.port</code> and <code>gpio.pin</code> accesses in the inline function? If not, why so, and does gcc apply other optimizations when it sees consts?</p>
  
  <p>In its full generality, <strong>what do I lose optimization-wise by using <code>static const</code> variables instead of defines,</strong> especially looking beyond simple integer constants?</p>