473,327 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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 2821
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*****@hotmail.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**********@Home.com
Jul 22 '05 #3
"Bob Hairgrove" <in*****@bigfoot.com> wrote in message
news:vp********************************@4ax.com...
On Fri, 22 Oct 2004 12:06:04 -0500, "cppsks" <sk*****@hotmail.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*****@bigfoot.com> wrote in message
news:vp********************************@4ax.com...
On Fri, 22 Oct 2004 12:06:04 -0500, "cppsks" <sk*****@hotmail.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_linkage_ 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
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...
2
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...
16
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
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...
3
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: ...
20
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
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?...
39
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...
5
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:...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.