Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6756377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:31:01+00:00 2026-05-26T13:31:01+00:00

I have this source file: // ConstPointer.cpp const short * const const_short_p_const = 0;

  • 0

I have this source file:

// ConstPointer.cpp
const short * const const_short_p_const = 0;
const short * const_short_p = 0;

and compiled it with and without debug infos (SUN C++ Compiler 5.10):

# CC ConstPointer.cpp -c -o ConstPointer.o
# CC -g ConstPointer.cpp -c -o ConstPointer-debug.o

Here are the symbol names of the object file without debug information:

# nm -C ConstPointer.o


ConstPointer.o:

[Index]   Value      Size    Type  Bind  Other Shndx   Name

[2]     |         0|       0|SECT |LOCL |0    |10     |
[3]     |         0|       0|SECT |LOCL |0    |9      |
[4]     |         0|       0|OBJT |LOCL |0    |6      |Bbss.bss
[1]     |         0|       0|FILE |LOCL |0    |ABS    |ConstPointer.cpp
[5]     |         0|       0|OBJT |LOCL |0    |3      |Ddata.data
[6]     |         0|       0|OBJT |LOCL |0    |5      |Dpicdata.picdata
[7]     |         0|       0|OBJT |LOCL |0    |4      |Drodata.rodata
[9]     |         4|       4|OBJT |GLOB |0    |3      |const_short_p
[8]     |         0|       4|OBJT |LOCL |0    |3      |const_short_p_const

Here are the symbol names of the object file with debug information:

# nm -C ConstPointer-debug.o


ConstPointer-debug.o:

[Index]   Value      Size    Type  Bind  Other Shndx   Name

[4]     |         0|       0|SECT |LOCL |0    |9      |
[2]     |         0|       0|SECT |LOCL |0    |8      |
[3]     |         0|       0|SECT |LOCL |0    |10     |
[10]    |         0|       4|OBJT |GLOB |0    |3      |$XAHMCqApZlqO37H.const_short_p_const
[5]     |         0|       0|NOTY |LOCL |0    |6      |Bbss.bss
[1]     |         0|       0|FILE |LOCL |0    |ABS    |ConstPointer.cpp
[6]     |         0|       0|NOTY |LOCL |0    |3      |Ddata.data
[7]     |         0|       0|NOTY |LOCL |0    |5      |Dpicdata.picdata
[8]     |         0|       0|NOTY |LOCL |0    |4      |Drodata.rodata
[9]     |         4|       4|OBJT |GLOB |0    |3      |const_short_p

Why has the variable const_short_p_const another symbol name? g++ does not change it, when compiling with debug information. It looks like a compiler bug to me. What do you think? The second const (constant pointer) leads to this.

EDIT for Drew Hall’s comment:
For example you have two files:

// ConstPointer.cpp
const short * const const_short_p_const = 0;

void foo();

int main(int argc, const char *argv[]) {
  foo();
  return 0;
}

and

// ConstPointer2.cpp
extern const short * const const_short_p_const;

void foo() {
  short x = *const_short_p_const;
}

Compiling is fine:

# CC ConstPointer2.cpp -g -c -o ConstPointer2.o
# CC ConstPointer.cpp -g -c -o ConstPointer.o      

but linking does not work because the symbols differ! The symbol name in ConstPointer2.o is const_short_p_const, but the symbol name in ConstPointer.o is $XAHMCqApZlqO37H.const_short_p_const.

# CC ConstPointer.o ConstPointer2.o -o ConstPointer
Undefined                       first referenced
 symbol                             in file
const_short_p_const                 ConstPointer2.o
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:31:01+00:00Added an answer on May 26, 2026 at 1:31 pm

    Maybe this is linked to the fact that a global const variable is implicitely static in C++?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using this file as source, I have a situation where I need to retrieve
I have this program that takes one argument for the source file and then
Say I have this small function in a source file static void foo() {}
I'm working on XSLT. I have this XML source file : <?xml version=1.0 encoding=UTF-8?>
I have a CMakeLists.txt file that looks like this: add_executable(exec1 exec1.c source1.c source2.c source3.c)
I have this source code from 2001 that I would like to compile. It
So I have Image like this (source: de-viz.ru ) I want to get something
So I have Image like this (source: de-viz.ru ) I want to get something
I have this long and complex source code that uses a RNG with a
I have this class: public class Source extends Node { protected DistributionSampler delay ;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.