HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: static const as a function argument
Operating System - HP-UX
1826291
Members
4666
Online
109692
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2010 05:25 AM
11-16-2010 05:25 AM
Hi,
Why does Foo::foo6() have a problem? (See below)
Thanks.
// =================================
HP-UX B.11.23 U ia64 1139467043 unlimited-user license
aCC: HP C/aC++ B3910B A.06.25.01 [May 16 2010]
92453-07 linker nm HP Itanium(R) B.12.54
// -----------
// Compilation
// -----------
> aCC +DD64 -AA a.cpp
ld: Unsatisfied symbol "Foo::STATIC_CONST_VALUE" in file a.o
1 errors.
// ===== File a.cpp : BEGIN =====
struct Foo
{
enum { ENUM_VALUE_VALUE = 121 };
const int CONST_VALUE;
static int STATIC_VALUE;
static const int STATIC_CONST_VALUE = 127;
Foo();
void foo (const int& i_val);
void foo1 ();
void foo2 ();
void foo3 ();
void foo4 ();
void foo5 ();
void foo6 ();
};
int Foo::STATIC_VALUE = 125;
Foo::Foo() : CONST_VALUE (123)
{
}
void Foo::foo (const int& i_val)
{
}
void Foo::foo1()
{
foo(119);
}
void Foo::foo2 ()
{
foo(ENUM_VALUE_VALUE);
}
void Foo::foo3 ()
{
foo(CONST_VALUE);
}
void Foo::foo4 ()
{
foo(STATIC_VALUE);
}
void Foo::foo5 ()
{
const int theValue = STATIC_CONST_VALUE;
foo(theValue);
}
void Foo::foo6 ()
{
foo(STATIC_CONST_VALUE); // This line causes linker error
}
int main()
{
return 0;
}
// ===== File a.cpp : END =====
// ===== nm a.o | c++filt : BEGIN =====
Symbols from a.o:
[Index] Value Size Type Bind O Shndx Name
[0] | 0| 0|NOTYP|LOCAL|0| UNDEF|
[16] | 0| 0|SECT |LOCAL|0|.HP.opt_annot|.HP.opt_annot
[17] | 0| 0|SECT |LOCAL|0|.IA_64.unwind_info|.IA_64.unwind_info
[18] | 0| 0|SECT |LOCAL|0|.IA_64.unwind_info|.IA_64.unwind_info
[20] | 0| 0|SECT |LOCAL|0|.IA_64.unwind_info|.IA_64.unwind_info
[21] | 0| 0|SECT |LOCAL|0|.IA_64.unwind_info|.IA_64.unwind_info
[22] | 0| 0|SECT |LOCAL|0|.IA_64.unwind_info|.IA_64.unwind_info
[23] | 0| 0|SECT |LOCAL|0|.IA_64.unwind_info|.IA_64.unwind_info
[24] | 0| 0|SECT |LOCAL|0|.IA_64.unwind_info|.IA_64.unwind_info
[25] | 0| 0|SECT |LOCAL|0|.IA_64.unwind_info|.IA_64.unwind_info
[15] | 0| 0|SECT |LOCAL|0|.IA_64.unwind_info|.IA_64.unwind_info
[19] | 0| 0|SECT |LOCAL|0|.IA_64.unwind_info|.IA_64.unwind_info
[3] | 0| 0|SECT |LOCAL|0|.debug_actual|.debug_actual
[2] | 0| 0|SECT |LOCAL|0|.debug_line|.debug_line
[14] | 0| 0|SECT |LOCAL|0|.debug_procs_abbrev|.debug_procs_abbrev
[4] | 0| 0|SECT |LOCAL|0| .text|.text
[5] | 0| 0|SECT |LOCAL|0| .text|.text
[6] | 0| 0|SECT |LOCAL|0| .text|.text
[11] | 0| 0|SECT |LOCAL|0| .text|.text
[7] | 0| 0|SECT |LOCAL|0| .text|.text
[8] | 0| 0|SECT |LOCAL|0| .text|.text
[9] | 0| 0|SECT |LOCAL|0| .text|.text
[10] | 0| 0|SECT |LOCAL|0| .text|.text
[13] | 0| 0|SECT |LOCAL|0| .text|.text
[12] | 0| 0|SECT |LOCAL|0| .text|.text
[38] | 0| 0|FUNC |GLOB |0| UNDEF|_Unwind_Resume
[36] | 0| 4|OBJT |GLOB |0| .sdata|Foo::STATIC_VALUE
[37] | 0| 0|OBJT |GLOB |0| UNDEF|Foo::STATIC_CONST_VALUE
[29] | 0| 32|FUNC |GLOB |0| .text|Foo::foo(int const&)
[30] | 0| 208|FUNC |GLOB |0| .text|Foo::foo1()
[31] | 0| 208|FUNC |GLOB |0| .text|Foo::foo2()
[32] | 0| 176|FUNC |GLOB |0| .text|Foo::foo3()
[33] | 0| 192|FUNC |GLOB |0| .text|Foo::foo4()
[34] | 0| 208|FUNC |GLOB |0| .text|Foo::foo5()
[35] | 0| 192|FUNC |GLOB |0| .text|Foo::foo6()
[27] | 0| 32|FUNC |GLOB |0| .text|Foo::Foo()(complete)
[28] | 0| 176|FUNC |GLOB |0| .text|Foo::Foo()(base)
[1] | 0| 0|FILE |LOCAL|0| ABS|a.cpp
[26] | 0| 16|FUNC |GLOB |0| .text|main
// ===== nm a.o | c++filt : END =====
Solved! Go to Solution.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2010 08:25 PM
11-16-2010 08:25 PM
Solution
>Why does Foo::foo6() have a problem?
Because you violated the ODR rule. You need to have a definition (one) for it.
The current Standard says you must also define Foo::STATIC_CONST_VALUE outside the class:
const int Foo::STATIC_CONST_VALUE;
9.4.2(4)
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.)
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?
Because you violated the ODR rule. You need to have a definition (one) for it.
The current Standard says you must also define Foo::STATIC_CONST_VALUE outside the class:
const int Foo::STATIC_CONST_VALUE;
9.4.2(4)
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.)
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2010 10:02 PM
11-16-2010 10:02 PM
Re: static const as a function argument
Dennis, thank you.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP