473,836 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

text,data and bss

i just got to know there are three different sections in which we can
divide our program
*Text section
*Data section
*Bss

i think text section contain our code,data section include heap,stack
(?) etc.

Can any body throw light on Bss section...
Nov 16 '08
27 13620
On Mon, 17 Nov 2008 15:27:52 -0600, Stephen Sprunk wrote:
Harald van Dijk wrote:
>Given

union {
double d;
char x[1000];
} u = { 0 };

u.d will be initialised to zero, but I was talking about the bytes that
follow u.d.

In that example, isn't the part of u.x not overlapping with u.d supposed
to be zero-filled as well?
No, it's not, and in the general case, it can't be:

union {
char x[sizeof(double) - 1];
double d;
} u = { 0 };

There isn't any way to zero-initialise the final byte of d. (I'm assuming
sizeof(double) is not 1.)
This example could be inefficient if all-bits-zero wasn't 0.0, forcing
the entire union into .data instead of .bss, but I don't think you'd get
"random bytes" in the non-overlapping part of u.x.
If real-world compilers don't clear out bits in floating point constants
that don't contribute to the value (admittedly, this is not by a
conforming compiler, but it's not one of the areas in which it doesn't
conform), it wouldn't surprise me if real-world compilers don't clear out
bytes in unions that don't contribute to the value.
Nov 17 '08 #21
On 17 Nov, 21:27, Stephen Sprunk <step...@sprunk .orgwrote:
Harald van Dk wrote:
On Mon, 17 Nov 2008 00:25:58 -0600, Stephen Sprunk wrote:
Harald van Dk wrote:
On Sun, 16 Nov 2008 22:27:37 +0000, Richard Tobin wrote:
If 0.0 is all zeros, then a zero-initialised section can be used for
it.
If it's not, then you need something like .data that can be
initialised
to any value. Neither case suggests a .bss that is not initialised at
all.
>Oh, sure, initialised to whatever random bytes the compiler happened to
have in memory when laying out the .data section or equivalent is
effectively uninitialised to me.
Uh, what? If all-bits-zero (which is what you'd get in .bss) does not
mean 0.0, then the compiler would instead create an entry in .data that
_does_ mean 0.0. There is no initialization to "whatever random bytes
the compiler happened to have in memory"; either way, the variable will
end up being 0.0.
Given
union {
double d;
char x[1000];
} u = { 0 };
u.d will be initialised to zero, but I was talking about the bytes that
follow u.d.

In that example, isn't the part of u.x not overlapping with u.d supposed
to be zero-filled as well?

This example could be inefficient if all-bits-zero wasn't 0.0, forcing
the entire union into .data instead of .bss, but I don't think you'd get
"random bytes" in the non-overlapping part of u.x.
I don't think it is possible for C to initialise both components of
the above union to zero - at least not in the general case. Where the
machine has a double zero representation that is not all zero bits it
is impossible to zero both.

James
Nov 17 '08 #22
jameskuyper wrote:
Stephen Sprunk wrote:
>Harald van Dk wrote:
...
>>Given

union {
double d;
char x[1000];
} u = { 0 };

u.d will be initialised to zero, but I was talking about the bytes that
follow u.d.
In that example, isn't the part of u.x not overlapping with u.d supposed
to be zero-filled as well?

No.
Sorry - that wasn't meant to be so abrupt - I accidentally sent that
message when I'd just barely started writing it.

6.2.6.1p6: "When a value is stored in an object of structure or union
type, including in a member object, the bytes of the object
representation that correspond to any padding bytes take
unspecified values."

6.2.6.1p7: "When a value is stored in a member of an object of union
type, the bytes of the object representation that do not correspond to
that member but do correspond to other members take unspecified values."

You're probably thinking of the following rule:

6.7.8p21: "... the remainder of the aggregate shall be initialized
implicitly the same as objects that have static storage duration."

However, unions are NOT aggregates, so this rule only applies to
structures or arrays.
Nov 18 '08 #23
Stephen Sprunk <st*****@sprunk .orgwrote:
Harald van D??k wrote:

Given

union {
double d;
char x[1000];
} u = { 0 };

u.d will be initialised to zero, but I was talking about the bytes that
follow u.d.

In that example, isn't the part of u.x not overlapping with u.d supposed
to be zero-filled as well?
Not so far, but there's a fair chance that C1X will require it.
--
Larry Jones

Kicking dust is the only part of this game we really like. -- Calvin
Nov 18 '08 #24
la************@ siemens.com writes:
Stephen Sprunk <st*****@sprunk .orgwrote:
>Harald van D??k wrote:
>
Given

union {
double d;
char x[1000];
} u = { 0 };

u.d will be initialised to zero, but I was talking about the bytes that
follow u.d.

In that example, isn't the part of u.x not overlapping with u.d supposed
to be zero-filled as well?

Not so far, but there's a fair chance that C1X will require it.
Really? How will something like this be handled?

union {
int i;
double d;
};

Suppose sizeof(double) sizeof(int), and double(0.0) isn't
represented as all-bits-zero.

Or consider:

union {
int i;
float f;
void *p;
}

Which member gets zeroed? Will this apply only to non-overlapping
members? (Obviously all top-level members overlap; this can apply
only to submembers.)

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 18 '08 #25
Keith Thompson wrote:
la************@ siemens.com writes:
>Stephen Sprunk <st*****@sprunk .orgwrote:
>>Harald van D??k wrote:
Given

union {
double d;
char x[1000];
} u = { 0 };

u.d will be initialised to zero, but I was talking about the bytes that
follow u.d.

In that example, isn't the part of u.x not overlapping with u.d supposed
to be zero-filled as well?

Not so far, but there's a fair chance that C1X will require it.

Really? How will something like this be handled?

union {
int i;
double d;
};

Suppose sizeof(double) sizeof(int), and double(0.0) isn't
represented as all-bits-zero.
If you are initializing d, nothing would change since there is no
non-overlapping part of i.

In the case where sizeof(int) sizeof(double), then the non-overlapping
bytes in i would be zero-filled. That is, in fact, what happens with
every implementation I've used (since they zero-fill all memory before
giving it to a process), which is part of why I had thought it was
required. (The is that I rarely use unions, so I keep thinking of the
rules for structs, which are similar but not identical.)
Or consider:

union {
int i;
float f;
void *p;
}

Which member gets zeroed? Will this apply only to non-overlapping
members? (Obviously all top-level members overlap; this can apply
only to submembers.)
See above. The proposed change would only affect the non-overlapping
parts of members that weren't explicitly initialized.

S
Nov 19 '08 #26
Stephen Sprunk <st*****@sprunk .orgwrites:
Keith Thompson wrote:
>la************@ siemens.com writes:
>>Stephen Sprunk <st*****@sprunk .orgwrote:
Harald van D??k wrote:
Given
>
union {
double d;
char x[1000];
} u = { 0 };
>
u.d will be initialised to zero, but I was talking about the
bytes that follow u.d.

In that example, isn't the part of u.x not overlapping with u.d
supposed to be zero-filled as well?

Not so far, but there's a fair chance that C1X will require it.
Really? How will something like this be handled?
union {
int i;
double d;
};
Suppose sizeof(double) sizeof(int), and double(0.0) isn't
represented as all-bits-zero.

If you are initializing d, nothing would change since there is no
non-overlapping part of i.

In the case where sizeof(int) sizeof(double), then the
non-overlapping bytes in i would be zero-filled. That is, in fact,
what happens with every implementation I've used (since they zero-fill
all memory before giving it to a process), which is part of why I had
thought it was required. (The is that I rarely use unions, so I keep
thinking of the rules for structs, which are similar but not
identical.)
>Or consider:
union {
int i;
float f;
void *p;
}
Which member gets zeroed? Will this apply only to non-overlapping
members? (Obviously all top-level members overlap; this can apply
only to submembers.)

See above. The proposed change would only affect the non-overlapping
parts of members that weren't explicitly initialized.
Given:

static union {
int i;
void *p[100];
} obj;

C99 currently states that i is initialized to 0, and the initial value
of p isn't specified. So with the proposed change, all bytes of obj.p
beyond the first sizeof(int) bytes will be set to 0, even if
all-bits-zero isn't a representation of a null pointer?

How is that useful?

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 19 '08 #27
Keith Thompson <ks***@mib.orgw rote:
la************@ siemens.com writes:

Not so far, but there's a fair chance that C1X will require it.

Really? How will something like this be handled?

union {
int i;
double d;
};

Suppose sizeof(double) sizeof(int), and double(0.0) isn't
represented as all-bits-zero.
The proposal is that the "extra" bytes be initialized to zero (actually,
it says that *all* the bytes are set to zero before the regular
initialization process occurs). How useful that is depends on the
actual types involved and their representations , but it reflects
existing practice on the vast majority of implementations .
--
Larry Jones

I keep forgetting that rules are only for little nice people. -- Calvin
Nov 19 '08 #28

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

Similar topics

9
6841
by: Stephen Saunders | last post by:
Hey Folks, This one currently has me stumped. I have to check for the existence of a carriage return (Enter key, hex 0D) in text data. First I tried: 'Check comment to not contain the CR (13) character For i = 1 To Len(txtComment.Text) On Error GoTo BogusComment2 If Mid(txtComment.Text, i, 1) = CStr(13) Then MsgBox "Comment cannot contain the enter character"
2
1788
by: leegold2 | last post by:
General DB questions, Why do we use null values? Why is it better than an empty field? What would be a real life situation were nulls are important to have? If I have a paragraph of text in a field of data type: TEXT. Can I search in this field? Maybe i mean, could i use SELECT on a table and get rows on the basis of a string or substring in the TEXT field? Thanks,
5
8597
by: adrian | last post by:
hi all this is my first post to this group, so pls bear with me while i try to make some sense. i am trying to create a sproc which uses dynamic sql to target a particuar table eg. '.' and perform some actions. i am using @tableID as a passes parameter for the sproc.
1
1793
by: Ola Theander | last post by:
Dear subscribers I'm currently creating a small application that will run at the end of a web installation to configure a SQL Server. For this task I have a SQL batch file in the same format as SQL Query Analyzer uses. I would prefer not to merge the content of this file into the source code of configuration application but instead keep the SQL commands in a text file included in the executable, pretty much like resource data, for...
9
2362
by: Susan Bricker | last post by:
Greetings. I am having trouble populating text data that represents data in my table. Here's the setup: There is a People Table (name, address, phone, ...) peopleID = autonumber key There is a Judge Table (information about judges) judgeID = autonumber key
6
4784
by: smilly | last post by:
This field is bound to a image data type in SQL server that is used to house big amounts of text how can I output the text data because right now I am getting System.Byte
5
1754
by: sirimanna | last post by:
hello, i'm new to VB...i like to know how to open some text data save in c: in to text box.. i know to save cord's to save data in text box in to c:..but i don't know how to get back that save text data in c: in to vbtext box thank u.
0
1316
by: Jack | last post by:
Hi, I do a webrequest and it returns some text data in a stream. I want to put this tyext data into a string. I've got it working just fine, but I have to put the text data into into a fixed-size buffer BEFORE I put it into a string (ConstBufferByteSize=1000000). This fixed size buffer wastes space. Is it possible to somehow assign it straight to a string, or somehow do this 'dynamically' ?
6
5254
by: aagarwal8 | last post by:
Hi, I am trying to write the contents of a textbox to a file in binary format. My code looks like this... private void btnWriteToFile_Click(object sender, EventArgs e) { FileStream fs = File.Open(@"D:\test.dat", FileMode.OpenOrCreate, FileAccess.Write); BinaryWriter bw = new BinaryWriter(fs);
9
5384
by: sillyr | last post by:
Hi - I use Access 2007. I have a two data fields that I would like to add together in a query and then have the query sum the data for the entire table. The problem is that one of the data fields has a data type of number and the other data field has a data type of text. The data filed with the text data type is a combo box with two fields on of which is a number and t he other is text. I tried to use the functions Val and Cint, but am not...
0
10844
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10548
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
10591
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
10254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7792
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6979
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
5826
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4452
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4016
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.