<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: static const as a function argument in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/static-const-as-a-function-argument/m-p/4713976#M660070</link>
    <description>&amp;gt;Why does Foo::foo6() have a problem?&lt;BR /&gt;&lt;BR /&gt;Because you violated the ODR rule.  You need to have a definition (one) for it.&lt;BR /&gt;&lt;BR /&gt;The current Standard says you must also define Foo::STATIC_CONST_VALUE outside the class:&lt;BR /&gt;const int Foo::STATIC_CONST_VALUE;&lt;BR /&gt;9.4.2(4)&lt;BR /&gt;&lt;BR /&gt;This is needed for your case where you are taking the address of the variable, to bind to the const ref parm of foo.  (Or the compiler is too dumb to do simple constant propagation.)&lt;BR /&gt;&lt;BR /&gt;The next Standard doesn't require the definition outside the class but I assume it says it is still needed if you take the address?</description>
    <pubDate>Wed, 17 Nov 2010 04:25:31 GMT</pubDate>
    <dc:creator>Dennis Handly</dc:creator>
    <dc:date>2010-11-17T04:25:31Z</dc:date>
    <item>
      <title>static const as a function argument</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/static-const-as-a-function-argument/m-p/4713975#M660069</link>
      <description>&lt;BR /&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;Why does Foo::foo6() have a problem?  (See below)&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;BR /&gt;&lt;BR /&gt;// =================================&lt;BR /&gt;HP-UX B.11.23 U ia64 1139467043 unlimited-user license&lt;BR /&gt;&lt;BR /&gt;aCC: HP C/aC++ B3910B A.06.25.01 [May 16 2010]&lt;BR /&gt;&lt;BR /&gt;92453-07 linker nm HP Itanium(R) B.12.54 &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;// -----------&lt;BR /&gt;// Compilation &lt;BR /&gt;// -----------&lt;BR /&gt;&amp;gt; aCC +DD64 -AA a.cpp&lt;BR /&gt;ld: Unsatisfied symbol "Foo::STATIC_CONST_VALUE" in file a.o&lt;BR /&gt;1 errors.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;// ===== File a.cpp : BEGIN =====&lt;BR /&gt;struct Foo&lt;BR /&gt;{&lt;BR /&gt; enum { ENUM_VALUE_VALUE = 121 };&lt;BR /&gt;  const int CONST_VALUE;&lt;BR /&gt;  static int STATIC_VALUE;&lt;BR /&gt; static const int STATIC_CONST_VALUE = 127;&lt;BR /&gt; &lt;BR /&gt; Foo();&lt;BR /&gt; void foo (const int&amp;amp; i_val);&lt;BR /&gt; &lt;BR /&gt; void foo1 ();&lt;BR /&gt; void foo2 ();&lt;BR /&gt; void foo3 ();&lt;BR /&gt; void foo4 ();&lt;BR /&gt; void foo5 ();&lt;BR /&gt; void foo6 ();&lt;BR /&gt;&lt;BR /&gt;};&lt;BR /&gt;&lt;BR /&gt;int Foo::STATIC_VALUE = 125;&lt;BR /&gt;&lt;BR /&gt;Foo::Foo() : CONST_VALUE (123) &lt;BR /&gt;{&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;void Foo::foo (const int&amp;amp; i_val) &lt;BR /&gt;{&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;void Foo::foo1()&lt;BR /&gt;{&lt;BR /&gt; foo(119);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;void Foo::foo2 ()&lt;BR /&gt;{&lt;BR /&gt; foo(ENUM_VALUE_VALUE);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;void Foo::foo3 ()&lt;BR /&gt;{&lt;BR /&gt; foo(CONST_VALUE);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;void Foo::foo4 ()&lt;BR /&gt;{&lt;BR /&gt; foo(STATIC_VALUE);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;void Foo::foo5 ()&lt;BR /&gt;{&lt;BR /&gt; const int theValue = STATIC_CONST_VALUE;&lt;BR /&gt; foo(theValue);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;void Foo::foo6 ()&lt;BR /&gt;{&lt;BR /&gt;  foo(STATIC_CONST_VALUE);  // This line causes linker error&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;int main()&lt;BR /&gt;{&lt;BR /&gt; return 0;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;// ===== File a.cpp : END =====&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;// ===== nm a.o | c++filt : BEGIN =====&lt;BR /&gt;&lt;BR /&gt;Symbols from a.o:&lt;BR /&gt;&lt;BR /&gt;[Index]    Value                  Size    Type  Bind  O Shndx    Name&lt;BR /&gt;&lt;BR /&gt;[0]      |                     0|       0|NOTYP|LOCAL|0|   UNDEF|&lt;BR /&gt;[16]     |                     0|       0|SECT |LOCAL|0|.HP.opt_annot|.HP.opt_annot&lt;BR /&gt;[17]     |                     0|       0|SECT |LOCAL|0|.IA_64.unwind_info|.IA_64.unwind_info&lt;BR /&gt;[18]     |                     0|       0|SECT |LOCAL|0|.IA_64.unwind_info|.IA_64.unwind_info&lt;BR /&gt;[20]     |                     0|       0|SECT |LOCAL|0|.IA_64.unwind_info|.IA_64.unwind_info&lt;BR /&gt;[21]     |                     0|       0|SECT |LOCAL|0|.IA_64.unwind_info|.IA_64.unwind_info&lt;BR /&gt;[22]     |                     0|       0|SECT |LOCAL|0|.IA_64.unwind_info|.IA_64.unwind_info&lt;BR /&gt;[23]     |                     0|       0|SECT |LOCAL|0|.IA_64.unwind_info|.IA_64.unwind_info&lt;BR /&gt;[24]     |                     0|       0|SECT |LOCAL|0|.IA_64.unwind_info|.IA_64.unwind_info&lt;BR /&gt;[25]     |                     0|       0|SECT |LOCAL|0|.IA_64.unwind_info|.IA_64.unwind_info&lt;BR /&gt;[15]     |                     0|       0|SECT |LOCAL|0|.IA_64.unwind_info|.IA_64.unwind_info&lt;BR /&gt;[19]     |                     0|       0|SECT |LOCAL|0|.IA_64.unwind_info|.IA_64.unwind_info&lt;BR /&gt;[3]      |                     0|       0|SECT |LOCAL|0|.debug_actual|.debug_actual&lt;BR /&gt;[2]      |                     0|       0|SECT |LOCAL|0|.debug_line|.debug_line&lt;BR /&gt;[14]     |                     0|       0|SECT |LOCAL|0|.debug_procs_abbrev|.debug_procs_abbrev&lt;BR /&gt;[4]      |                     0|       0|SECT |LOCAL|0|   .text|.text&lt;BR /&gt;[5]      |                     0|       0|SECT |LOCAL|0|   .text|.text&lt;BR /&gt;[6]      |                     0|       0|SECT |LOCAL|0|   .text|.text&lt;BR /&gt;[11]     |                     0|       0|SECT |LOCAL|0|   .text|.text&lt;BR /&gt;[7]      |                     0|       0|SECT |LOCAL|0|   .text|.text&lt;BR /&gt;[8]      |                     0|       0|SECT |LOCAL|0|   .text|.text&lt;BR /&gt;[9]      |                     0|       0|SECT |LOCAL|0|   .text|.text&lt;BR /&gt;[10]     |                     0|       0|SECT |LOCAL|0|   .text|.text&lt;BR /&gt;[13]     |                     0|       0|SECT |LOCAL|0|   .text|.text&lt;BR /&gt;[12]     |                     0|       0|SECT |LOCAL|0|   .text|.text&lt;BR /&gt;[38]     |                     0|       0|FUNC |GLOB |0|   UNDEF|_Unwind_Resume&lt;BR /&gt;[36]     |                     0|       4|OBJT |GLOB |0|  .sdata|Foo::STATIC_VALUE&lt;BR /&gt;[37]     |                     0|       0|OBJT |GLOB |0|   UNDEF|Foo::STATIC_CONST_VALUE&lt;BR /&gt;[29]     |                     0|      32|FUNC |GLOB |0|   .text|Foo::foo(int const&amp;amp;)&lt;BR /&gt;[30]     |                     0|     208|FUNC |GLOB |0|   .text|Foo::foo1()&lt;BR /&gt;[31]     |                     0|     208|FUNC |GLOB |0|   .text|Foo::foo2()&lt;BR /&gt;[32]     |                     0|     176|FUNC |GLOB |0|   .text|Foo::foo3()&lt;BR /&gt;[33]     |                     0|     192|FUNC |GLOB |0|   .text|Foo::foo4()&lt;BR /&gt;[34]     |                     0|     208|FUNC |GLOB |0|   .text|Foo::foo5()&lt;BR /&gt;[35]     |                     0|     192|FUNC |GLOB |0|   .text|Foo::foo6()&lt;BR /&gt;[27]     |                     0|      32|FUNC |GLOB |0|   .text|Foo::Foo()(complete)&lt;BR /&gt;[28]     |                     0|     176|FUNC |GLOB |0|   .text|Foo::Foo()(base)&lt;BR /&gt;[1]      |                     0|       0|FILE |LOCAL|0|     ABS|a.cpp&lt;BR /&gt;[26]     |                     0|      16|FUNC |GLOB |0|   .text|main&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;// ===== nm a.o | c++filt : END =====&lt;BR /&gt;</description>
      <pubDate>Tue, 16 Nov 2010 13:25:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/static-const-as-a-function-argument/m-p/4713975#M660069</guid>
      <dc:creator>Alex Vinokur</dc:creator>
      <dc:date>2010-11-16T13:25:04Z</dc:date>
    </item>
    <item>
      <title>Re: static const as a function argument</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/static-const-as-a-function-argument/m-p/4713976#M660070</link>
      <description>&amp;gt;Why does Foo::foo6() have a problem?&lt;BR /&gt;&lt;BR /&gt;Because you violated the ODR rule.  You need to have a definition (one) for it.&lt;BR /&gt;&lt;BR /&gt;The current Standard says you must also define Foo::STATIC_CONST_VALUE outside the class:&lt;BR /&gt;const int Foo::STATIC_CONST_VALUE;&lt;BR /&gt;9.4.2(4)&lt;BR /&gt;&lt;BR /&gt;This is needed for your case where you are taking the address of the variable, to bind to the const ref parm of foo.  (Or the compiler is too dumb to do simple constant propagation.)&lt;BR /&gt;&lt;BR /&gt;The next Standard doesn't require the definition outside the class but I assume it says it is still needed if you take the address?</description>
      <pubDate>Wed, 17 Nov 2010 04:25:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/static-const-as-a-function-argument/m-p/4713976#M660070</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-11-17T04:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: static const as a function argument</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/static-const-as-a-function-argument/m-p/4713977#M660071</link>
      <description>Dennis, thank you.</description>
      <pubDate>Wed, 17 Nov 2010 06:02:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/static-const-as-a-function-argument/m-p/4713977#M660071</guid>
      <dc:creator>Alex Vinokur</dc:creator>
      <dc:date>2010-11-17T06:02:34Z</dc:date>
    </item>
  </channel>
</rss>

