variable allocated from stack/bss ??

C

CBFalconer

MQ said:
This is exactly the sort of pompous vision that you can fight to your
dying days and will never win. It is an unmoderated newsgroup. People
will make their own judgement on what they want to post.

This is precisely the sort of stupid and pompous attitude that
destroys newsgroups. I assume that whenever you have the urge to
urinate you whip it out then and there. Meanwhile please cease
defecating in public.
 
K

Keith Thompson

William Hughes said:
Piffle. A sufficient answer would at least have pointed out that
the question of memory layout are
implementation specific. To omit this is to make the same
"all the world is an X machine" error made by the OP.
Since this is a mistake associated with programmers of limited
experience, it invites that assumption about you.

Yes, that's a very important point.

All the information that's been posted here about stack and BSS may or
may not be correct for most platforms, or for one specific platform.
But the fact that the C language does not refer to "stack" or "BSS" is
critical. Not bothering to mention that fact to the OP was a
disservice.

The posters in this thread who have talked about stack and BSS as if
they're universal concepts, or as if they're part of the C language,
have been misleading anyone who reads their articles. Anyone who
says, without qualification, that local variables in C are allocated
"on the stack" and globals area allocated "in BSS" does not understand
C.

Even if you (that's a generic "you") believe that we should be
discussing stack and BSS here in comp.lang.c, you should *at least*
acknowledge that they are features of some implementations, not of the
language.
 
D

Default User

santosh wrote:

The stack and the layout of the program in memory is subtly different
according to the hardware, the operating system, the compiler that
happens to compile the language, and the linker and/or loader. These
are specifically implementation and machine dependant details, and are
not topical for a group that deals with the abstract form of the
language.

And for the most part, a newbie doesn't NEED to know this. Learning the
various storage duration and scoping rules cover the vast majority of
cases that a beginner will deal with.

For the most part it doesn't matter where something is stored, only its
behavior.




Brian
 
J

jacob navia

Kenneth Brody a écrit :
In that case, why do you insist that those who post replies must
follow your ideas on how to post?

And "unmoderated" doesn't mean "open discussion on any topic you
feel like".

I consider that technical notions like "uninitialized variables"
and the mapping of the diffferent data sections of the language
to the actual sections of an executable is not at all off topic.

I am not speaking about "any topic" but about a topic related to
C. The argument of heathfield and co was that I was incorrect.

No concrete example was advance to prove where the argumentation
I used could be wrong. I can prove my point of view with concrete
examples of two OS where what I said is right: Windows and Unix.

AND besides,

This is unmoderated group, so even if we agree on the topic
(the C language) each one of us has a different opinion about
what that is.
 
R

Richard Heathfield

jacob navia said:
I am not speaking about "any topic" but about a topic related to
C.

No, you're talking about a topic related to a particular kind of platform.
The argument of heathfield and co was that I was incorrect.

Yes, in an impressive number of ways.
No concrete example was advance to prove where the argumentation
I used could be wrong.

(1) Concrete examples are unnecessary - it can be shown from the Standard
that it does not have anything to say on the subjects of "bss section" and
"stack section", and such things are mere implementation details, which are
best discussed in newsgroups dealing with those implementations.
I can prove my point of view with concrete
examples of two OS where what I said is right: Windows and Unix.

That doesn't prove your point at all. It merely demonstrates that some
implementations behave in a certain way. That does not mean that all
implementations behave in that way, or that any implementation is required
to behave in that way.
AND besides,

This is unmoderated group, so even if we agree on the topic
(the C language) each one of us has a different opinion about
what that is.

It is to avoid such differences of opinion that the language was
standardised in the first place. Duh.
 
B

Ben Pfaff

jacob navia said:
I consider that technical notions like "uninitialized variables"
and the mapping of the diffferent data sections of the language
to the actual sections of an executable is not at all off topic.

Why does everyone keep referring to variables stored in the bss
section (in some implementations) as uninitialized? They are
initialized to numeric zero or the null pointer.
 
K

Keith Thompson

Ben Pfaff said:
Why does everyone keep referring to variables stored in the bss
section (in some implementations) as uninitialized? They are
initialized to numeric zero or the null pointer.

As far as I know (and I could very easily be mistaken), the bss
section, on systems that have such a thing, is initialized to
all-bits-zero. This implies that the bss section cannot be used for
pointers *unless* all-bits-zero happens to be a null pointer, or
unless any pointers are initialized by explicit code during program
startup.

My suspicion is that all system that use "bss" have all-bits-zero null
pointers. Since it's been quite thoroughly established that null
pointers *don't* have to be all-bits-zero, this is yet another reason
not to assume that "bss" is either universal or directly relevant to
the C language.

I know there have been systems with null pointers not represented as
all-bits-zero (though I don't know if any such systems are recent
enough to conform to C90, much less C99). Did this affect program
startup and the use of bss or something similar?

All this also applies to floating-point types.
 
M

MQ

Chris said:
How tolerant to you want us to be? Should we answer questions on C++?
What about Qt? Sockets? HTTP? MS Access? HTML? Graphic design? CCGs?
Compilation technology? The x86 instruction set? The ARM instruction
set? RISC OS? Go on, why not? How about Swing? I've got this interpreted
language and the interpreter's written in C, so the language is on-
topic, right? And language design. How about closures and objects,
they're part of C#, so they're topical, aren't they?

There are some topics that are clearly off-topic, and some that are
marginal. It is up to each individual to decide this, not the group
"moderators". When someone answers a question that's off-topic, we
always see the bureaucracy chime in with "chapter and verse" bollocks.
I know that the topic is not standard C, but I don't care. That is
what I mean by intolerance. And I refute the accusation that the
answer is misleading. Misleading in a universal context, maybe, but
not in this case...

MQ
 
K

Keith Thompson

MQ said:
There are some topics that are clearly off-topic, and some that are
marginal. It is up to each individual to decide this, not the group
"moderators".

There are no moderators. There are only individuals. As an
individual, I have decided, in accordance with a fairly broad
consensus of knowledgeable regulars (other individuals), that some
things are off-topic, for reasons that have been explained at great
length. "BSS" is one of these things.
When someone answers a question that's off-topic, we
always see the bureaucracy chime in with "chapter and verse" bollocks.
I know that the topic is not standard C, but I don't care.

Perhaps you should. Standard C is what this newsgroup is about.

But the "chapter and verse" challenges are usually in response to
off-topic *answers*, not off-topic questions.
That is
what I mean by intolerance. And I refute the accusation that the
answer is misleading. Misleading in a universal context, maybe, but
not in this case...

You haven't refuted the accusation, you've merely denied it. (Or
maybe I'm misusing the words "refute" and "deny", but you get the
idea.)

Here's the article that started this thread, posted by "onkar":
| Given the following code & variable i .
|
| int main(int argc,char **argv){
| int i;
| printf("%d\n",i);
| return 0;
|
| }
|
| here i is allocated from bss or stack ?
|
| I think it is stack,because it prints garbage value; If it were
| allocated from bss the default value would be 0
| please tell me if I am right or wrong ??

And here's the initial response, posted by "MQ" (that's you):
| onkar wrote:
[quoted text deleted]
|
| Local variables are stored on the stack. BSS is used for uninitialized
| global or static variables.

The question was asked in comp.lang.c. You replied with
system-specific information that may be accurate for some particular
implementations (perhaps even most of them), but is not specified by
the C language, and that very likely is untrue or meaningless for some
conforming C implementations. You did not qualify your answer in any
way. The OP likely was starting out with the misconception that "BSS"
and "stack" are defined by the C language; you reinforced that
misconception.

Furthermore, the phrase "uninitialized global or static variables" is
potentially misleading. You probably meant to refer to variables that
are not *explicitly* initialized; such variables (if they have static
storage duration) are implicitly initialized to zero, not
uninitialized.

For comparison, here's what I probably would have written if I'd seen
the thread sooner:
========================================
Roughly, yes, it's allocated on the stack, but read on.

Strictly speaking, the C language has no concept of "bss" or "stack".
It defines several storage durations, namely "static", "automatic",
and "allocated".

Variables with static storage duration exist throughout the lifetime
of the program. They're either declared outside of any function, or
inside a function with the 'static" keyword. Such variables are
implicitly initialized to zero if they don't have an explicit
initialier. Some implementations may allocate such variables from a
"bss" section, but that's system-specific; consult another newsgroup
or your system's documentation for more information about that.

Variables with automatic storage duration are declared inside
functions *without* the "static" keyword, and exist only until the end
of their scope; your variable "i" is an example of this. (On many
implementations, automatic variables are allocated on a "stack".)
Unlike a static variable, an automatic variable that isn't explicitly
initialized has a garbage value until you assign something to it.

Allocated storage duration is for objects created by the
malloc() function. Such objects exist from the time they're created
until they're destroyed by a call to free(). (It's a little more
complicated than that; see also the calloc() and realloc() functions.)

Finally, you need to add a "#include <stdio.h>" to be able to use the
printf function. If your compiler didn't warn you about this, you
should set whatever options it needs to persuade it to do so. It may
happen to work without the "#include <stdio.h>", but it's not
guaranteed to do so.
========================================

This answers the OP's question *and* teaches enough fundamental
concepts of C for the answer to make sense.
 
T

Tak-Shing Chan

Some of don't regard that as necessarily bad.

How tolerant to you want us to be? Should we answer questions on C++?
What about Qt? Sockets? HTTP? MS Access? HTML? Graphic design? CCGs?
Compilation technology? The x86 instruction set? The ARM instruction
set? RISC OS? Go on, why not? How about Swing? I've got this interpreted
language and the interpreter's written in C, so the language is on-
topic, right? And language design. How about closures and objects,
they're part of C#, so they're topical, aren't they?

Slippery slope argument. Translation: irrelevant, or
inconsistent, or both.
What we're here for is to offer (and receive) help on & discuss the C
language as defined by the Standards and "closely related" stuff.

What is "closely related" for you might not be "closely
related" for others. Problem: who decides what is related and
how close is close enough?
There's
plenty of C-stuff to discuss, it's not as though we're short of material,
and every atopical item is clutter, makes it harder to see the C stuff,

The clutter metric: count the number of posts containing
viewpoints that are not directly supportable by C&V, divided by
the total number of posts. I figured that the clutter metric is
above 90% on comp.lang.c.

Tak-Shing
 
C

CBFalconer

Richard said:
jacob navia said:
.... snip ...


(1) Concrete examples are unnecessary - it can be shown from the
Standard that it does not have anything to say on the subjects of
"bss section" and "stack section", and such things are mere
implementation details, which are best discussed in newsgroups
dealing with those implementations.

Further proof:

[1] c:\stds>grep bss n869.txt

[1] c:\stds>grep section n869.txt
if-section
if-section:
[#4] The implementation can process and skip sections of
[#1] The functions in this section manage the floating-point
if-section
(6.10.1) if-section:
[#1] This section identifies code transformations that might

Note how handy it is to have a text version of the standard.
 
M

MQ

Keith said:
Yes, that's a very important point.

All the information that's been posted here about stack and BSS may or
may not be correct for most platforms, or for one specific platform.
But the fact that the C language does not refer to "stack" or "BSS" is
critical. Not bothering to mention that fact to the OP was a
disservice.

The posters in this thread who have talked about stack and BSS as if
they're universal concepts, or as if they're part of the C language,
have been misleading anyone who reads their articles. Anyone who
says, without qualification, that local variables in C are allocated
"on the stack" and globals area allocated "in BSS" does not understand
C.

Even if you (that's a generic "you") believe that we should be
discussing stack and BSS here in comp.lang.c, you should *at least*
acknowledge that they are features of some implementations, not of the
language.

And I have said so above. But for intelligent people, you are finding
it hard to grasp that the OP does not care about all implementations,
just his/hers. The answer is correct in the context of his question.
This is the last time I will say this.
 
W

William Hughes

MQ wrote:

said:
But for intelligent people, you are finding
it hard to grasp that the OP does not care about all implementations,
just his/hers.

Piffle. You have absolutely no way of knowing this.
And even if true, your answer remains woefully incomplete.

- William Hughes
 
K

Keith Thompson

MQ said:
Keith Thompson wrote: [...]
Even if you (that's a generic "you") believe that we should be
discussing stack and BSS here in comp.lang.c, you should *at least*
acknowledge that they are features of some implementations, not of the
language.

And I have said so above. But for intelligent people, you are finding
it hard to grasp that the OP does not care about all implementations,
just his/hers. The answer is correct in the context of his question.
This is the last time I will say this.

First, you don't know that.

Second, even if the OP doesn't care about it, that's no reason not to
tell him anyway. He's free to ignore it, and he's not the only person
reading your followup.
 
R

Richard Heathfield

MQ said:
The answer is correct in the context of his question.
This is the last time I will say this.

Good, because you're mistaken. This, alas, is not the last time I will say
this.
 
C

Chris Dollin

Tak-Shing Chan said:
Slippery slope argument. Translation: irrelevant, or
inconsistent, or both.

No. I'm attempting to establish that either MQ thinks /all/ of these
are topical, or that some are not - and hence that "I can post what
I like" isn't an option.
What is "closely related" for you might not be "closely
related" for others. Problem: who decides what is related and
how close is close enough?

We do. Who else is there? Who else is interested?

We know what the core topic is; we have notions of "closer" which I'd
expect to be broadly compatible; we have a bunch of participants
who (a) make valuable contributions and (b) take more-or-less
compatible positions on what's topical. Feel free to argue the
abstracts if you wish.
The clutter metric: count the number of posts containing
viewpoints that are not directly supportable by C&V, divided by
the total number of posts. I figured that the clutter metric is
above 90% on comp.lang.c.

That's not /the/ clutter metric, that's /a/ clutter metric. If
I was looking for a metric, that's not the one I'd pick, but
since you don't say what the pragmatic significance of your
90% estimate is, I'll wait.
 
T

Tak-Shing Chan

No. I'm attempting to establish that either MQ thinks /all/ of these
are topical, or that some are not - and hence that "I can post what
I like" isn't an option.

``I can post what I like'' is exactly the slippery slope in
question. MQ's position is that ``the question is somewhat
off-topic'', but ``how hard is it for the CLC bureaucracy to at
least help them out, *then* tell them that they are at the wrong
newsgroup''? You are implying that this position would lead to
``I can post what I like'', the worst case scenerio. Now I would
call this a standard slippery slope argument.
We know what the core topic is; we have notions of "closer" which I'd
expect to be broadly compatible; we have a bunch of participants
who (a) make valuable contributions and (b) take more-or-less
compatible positions on what's topical. Feel free to argue the
abstracts if you wish.

On the contrary, I believe that there exist a large spectrum
of positions. For example, I would classify Jacob Navia as a
liberal, Steve Summit as a moderate, and Keith Thompson as a
conservative. I do not believe that these three regulars take
``compatible positions on what's topical''.
That's not /the/ clutter metric, that's /a/ clutter metric. If
I was looking for a metric, that's not the one I'd pick, but
since you don't say what the pragmatic significance of your
90% estimate is, I'll wait.

The pragmatic significance is that liberal posters can cite
this metric and say ``take the log from your eyes'' or ``those
who never post OT can cast the first stone''. :)

Tak-Shing
 
R

Richard Heathfield

[staying out of this for the most part, but just one point begs to be made]

Tak-Shing Chan said:
On Fri, 1 Dec 2006, Chris Dollin wrote:


On the contrary, I believe that there exist a large spectrum
of positions. For example, I would classify Jacob Navia as a
liberal, Steve Summit as a moderate, and Keith Thompson as a
conservative. I do not believe that these three regulars take
``compatible positions on what's topical''.

Chris specifically mentioned "(a) make valuable contributions". Do you have
a better example for "liberal"? If so, then maybe you have the makings of a
point.

<snip>
 
C

Chris Dollin

Tak-Shing Chan said:
``I can post what I like'' is exactly the slippery slope in
question. MQ's position is that ``the question is somewhat
off-topic'', but ``how hard is it for the CLC bureaucracy to at
least help them out, *then* tell them that they are at the wrong
newsgroup''? You are implying that this position would lead to
``I can post what I like'', the worst case scenerio. Now I would
call this a standard slippery slope argument.

Actually I was referring to another of MQ's posts, according to
my recollection of them, in which I believe he said words to
the effect of "this isn't a moderated newsgroup, posters can
post whatever they like". Those with more gfu than I can probably
find that post and correct me if necessary.
On the contrary, I believe that there exist a large spectrum
of positions. For example, I would classify Jacob Navia as a
liberal, Steve Summit as a moderate, and Keith Thompson as a
conservative. I do not believe that these three regulars take
``compatible positions on what's topical''.

I believe that that collection fails my precondition. Sorry.
The pragmatic significance is that liberal posters can cite
this metric and say ``take the log from your eyes'' or ``those
who never post OT can cast the first stone''. :)

That's not helpful about the pragmatic significance -- no matter what
the number is, your liberals can say the same thing. Maybe 90% is
to be expected (no matter how topical we try to stay), maybe 10%
would be optimal. Also you're now treating all offtopic posts as
equally clutterful -- no matter who made them or why or in what
context.

I don't believe we need to quantify clutter to have a sense of
when there's more or less of it, nor to have an appreciation
of when there's too much. Eventually "too much" is a reason for
contributors to abandon ship and render the newsgroup useless
as a source of help on C-the-language.
 
T

Tak-Shing Chan

[staying out of this for the most part, but just one point begs to be made]

Tak-Shing Chan said:
On the contrary, I believe that there exist a large spectrum
of positions. For example, I would classify Jacob Navia as a
liberal, Steve Summit as a moderate, and Keith Thompson as a
conservative. I do not believe that these three regulars take
``compatible positions on what's topical''.

Chris specifically mentioned "(a) make valuable contributions". Do you have
a better example for "liberal"? If so, then maybe you have the makings of a
point.

With regards Jacob, I think we can agree to disagree.

How about Chris Torek? He is arguably the most valuable
contributor to this group, and is also liberal enough to have
posted UNIX and assembly language stuffs here.

Tak-Shing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top