473,803 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

question about const and text segment

I have been working on making a constant array available for the clients.
However, it is placing it in the text segment, and external references
result in unresolved references to the array. Taking the const off the
definition solves the problem (the variable is placed in the data segment).

Is this how const globals are supposed to work, or did the linker screw up?

Thanks.
Jul 22 '05 #1
4 2849
cppsks wrote:
I have been working on making a constant array available for the clients.
However, it is placing it in the text segment, and external references
result in unresolved references to the array. Taking the const off the
definition solves the problem (the variable is placed in the data segment).

Is this how const globals are supposed to work, or did the linker screw up?

Did you declare it 'extern'?

V
Jul 22 '05 #2
On Fri, 22 Oct 2004 12:06:04 -0500, "cppsks" <sk*****@hotmai l.com>
wrote:
I have been working on making a constant array available for the clients.
However, it is placing it in the text segment, and external references
result in unresolved references to the array. Taking the const off the
definition solves the problem (the variable is placed in the data segment).

Is this how const globals are supposed to work, or did the linker screw up?

Thanks.


C++ has no meaning for "segments" which are operating-system
dependent.

Did you declare the array with the "extern" keyword and export the
symbol from your executable?

--
Bob Hairgrove
No**********@Ho me.com
Jul 22 '05 #3
"Bob Hairgrove" <in*****@bigfoo t.com> wrote in message
news:vp******** *************** *********@4ax.c om...
On Fri, 22 Oct 2004 12:06:04 -0500, "cppsks" <sk*****@hotmai l.com>
wrote:
I have been working on making a constant array available for the clients.
However, it is placing it in the text segment, and external references
result in unresolved references to the array. Taking the const off the
definition solves the problem (the variable is placed in the data segment).
Is this how const globals are supposed to work, or did the linker screw up?
Thanks.


C++ has no meaning for "segments" which are operating-system
dependent.

Did you declare the array with the "extern" keyword and export the
symbol from your executable?


No, the array was declared in the header file as const (originally).
However, there were references to that array in the code and I guess if the
array is in the text segment, you can't refer to that address? I don't
know - that's why I am asking about this on this group. Thanks.

Other than the array being "const" (only readable), what other
"side-effects" are possible when it's const? Does it automatically go in the
text segment? Will there not a symbol generated for it?

Thanks.

Jul 22 '05 #4
cppsks wrote:
"Bob Hairgrove" <in*****@bigfoo t.com> wrote in message
news:vp******** *************** *********@4ax.c om...
On Fri, 22 Oct 2004 12:06:04 -0500, "cppsks" <sk*****@hotmai l.com>
wrote:

I have been working on making a constant array available for the clients.
However, it is placing it in the text segment, and external references
result in unresolved references to the array. Taking the const off the
definition solves the problem (the variable is placed in the data
segment).
Is this how const globals are supposed to work, or did the linker screw
up?
Thanks.


C++ has no meaning for "segments" which are operating-system
dependent.

Did you declare the array with the "extern" keyword and export the
symbol from your executable?

No, the array was declared in the header file as const (originally).
However, there were references to that array in the code and I guess if the
array is in the text segment, you can't refer to that address? I don't
know - that's why I am asking about this on this group. Thanks.

Other than the array being "const" (only readable), what other
"side-effects" are possible when it's const? Does it automatically go in the
text segment? Will there not a symbol generated for it?


Every object declared 'const' has _internal_linka ge_ by default. That
[usually] means that there is no way to get to it from another module.

What you have when you put your 'const' in a header is a bunch of those
consts all over the place. If you intend to have a const array of chars
shared between modules, you need to

(a) declare it in the header as such:

extern char const array[];

(b) define it in _one_ of the source files as such:

extern char const array[] = "contents of the shared array";

Then every module that includes the header with the declaration will gain
access to the array defined in one of your source modules.

V
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2091
by: Sims | last post by:
Hi, I have some small questions that have never been any problems, (for my compiler?), but always make me curious. So here goes... what does the standard sday about the 'if' statement? for example if i have,
2
2466
by: Bryan Parkoff | last post by:
I create one 32 Bits variable and four pointer variables. Four pointer variables link or point to one 32 Bits variable. Each pointer variable is 8 Bits. Look at my example below. unsigned int AA = 0; unsigned char* const AA_Byte1 = (unsigned char*)&AA; unsigned char* const AA_Byte2 = (unsigned char*)&AA + 1; unsigned char* const AA_Byte3 = (unsigned char*)&AA + 2; unsigned char* const AA_Byte4 = (unsigned char*)&AA + 3;
16
2742
by: Kitty | last post by:
Hi, everyone. Given a vector<int>, what is the fastest way to find out whether there is a repeated element in it? The result is just "true" or "false". Thanks. Kitty
9
1916
by: siliconwafer | last post by:
Hi All, Where is an identifier with a 'const' keyword given physical space in RAM ? Is it on stack or heap or data segment depending on storage class or is it treated as a part of code ,so kept in code segment? What is the case with #define statements?
3
2756
by: R. P. | last post by:
Subject: XSLT to transform a flat XML file into a structured text file I have an XML file that lists the PDF file segment names and titles of a larger document and looks something like this: <DOCUMENT> ...... ...... some lead elements ...... <SEGMENT_LIST>
20
3571
by: liujiaping | last post by:
I'm confused about the program below: int main(int argc, char* argv) { char str1 = "abc"; char str2 = "abc"; const char str3 = "abc"; const char str4 = "abc"; const char* str5 = "abc";
3
1429
by: Sachin | last post by:
Hi Folks, I have one query in regarding const varible interpretaion by C/C++ compiler. How Compiler actually differentiate between normal stack varible and const varible during program execution? Regards, Sachin
39
2798
by: Leonardo Korndorfer | last post by:
Hi, I'm litle confused by the const modifier, particularly when use const char* or char*. Some dude over here said it should be const char when you dont modify it content inside the function, I read somewhere that it when you won't modify after its initialization... So when exactly do I use one or another? Is it *wrong* not use const when I should?
5
1491
by: Eric | last post by:
Dear All: In the process of reading the FAQ, I have some questions here is the question from 1.13(in the new edition maybe 1.32). quot: ================================================================== What is the difference between these initializations? char a = "string literal"; char *p = "string literal";
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10309
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10289
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9119
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6840
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5496
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3795
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.