with respect to the memory

J

jesjak

thanks a lot Lew Pitcher.

one more doubt i have it is: we are declaring a structure and the
memory for that structure will be allocated only when i creat some
objects to that one right?
so where the momory will be allocated for structure signature and for
objects?

i will be thankfull if you or someone clarify this one too

thanks
 
W

Walter Roberson

one more doubt i have it is: we are declaring a structure and the
memory for that structure will be allocated only when i creat some
objects to that one right?
so where the momory will be allocated for structure signature and for
objects?

That's going to depend upon the compiler.

No space needs to be allocated for the "structure signature"
(whatever that is exactly): the offsets of structure members
are constants, so all of the code to access them can be compiled
right into the executable.

Objects are allocated in whatever kind of storage you declared
for them -- static, auto, dynamic. The exact (or even relative)
location of these types of memory in an executable is compiler dependant.
 
L

Lew Pitcher

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

thanks a lot Lew Pitcher.

You're welcome.
one more doubt i have it is: we are declaring a structure and the
memory for that structure will be allocated only when i creat some
objects to that one right?

You have the concept correct.
so where the momory will be allocated for structure signature and for
objects?

You have asked two questions here. Lets separate them so that the answers will
be clear.

Q1: Where will the memory be allocated for the structure definition?
Q2: Where will the memory be allocated for a specific declaration of an object
of a particular structure?

Question 1 is fairly simple: there is no memory allocated to a structure
definition. Period.

Question 2 is a little more complicated, and can be answered in several ways.
The pedants here might take exception to my answer, and they will provide
better, more accurate responses.

a) It depends. More specifically, it depends on whether you declare the object
as a static, an auto, or an extern, and it depends on whether or not you
provide an initializer for the contents of the object.

b) C makes no distinction between BSS and DATA. In fact, those terms have
nothing to do with C as a language. They /do/ have to do with the
implementation of your local C compiler on your local system, though. The best
we can tell you is that if you declare the object as 'static', the language
guarantees that the object will reside in the space set aside for 'static'
objects, and if you declare the object as 'auto', then the object will reside
in the space set aside for 'auto' objects. These two spaces /may/ be the same
physical space, or may be different physical spaces - that's beyond the
definition of the language.

i will be thankfull if you or someone clarify this one too


HTH
- --
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
- ---------- Slackware - Because I know what I'm doing. ------


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Armoured with GnuPG

iD8DBQFGVGD8agVFX4UWr64RAvI1AJ0VOhE1JKZqn7IvR1QdTiDkR9nGxgCfaqkp
qhejG0h7hHuEs8USxsC5h7I=
=deLg
-----END PGP SIGNATURE-----
 
K

Keith Thompson

Lew Pitcher said:
b) C makes no distinction between BSS and DATA. In fact, those terms
have nothing to do with C as a language. They /do/ have to do with
the implementation of your local C compiler on your local system,
though. The best we can tell you is that if you declare the object
as 'static', the language guarantees that the object will reside in
the space set aside for 'static' objects, and if you declare the
object as 'auto', then the object will reside in the space set aside
for 'auto' objects. These two spaces /may/ be the same physical
space, or may be different physical spaces - that's beyond the
definition of the language.

I'm going to quibble about the phrase "the space set aside". There
needn't be any space specifically set aside for either static or auto
objects.

All we can really say is that static objects exist during the entire
execution of the program, and auto objects exist only during the
execution of the enclosing compound statement.

(A compiler may vary this as long as any such variation has no visible
effect; for example, a declared object might not be stored anywhere if
the program never access it, or an auto object may be stored as if it
were static if the compiler can prove that the enclosing function is
never called recursively. The latter, as far as I know, is not a
likely thing for a compiler to do, since it doesn't really save time
or space.)
 
C

CBFalconer

one more doubt i have it is: we are declaring a structure and the
memory for that structure will be allocated only when i creat some
objects to that one right? so where the momory will be allocated
for structure signature and for objects?

See the following sig. Without proper quoting and linking to
previous messages this is totally meaningless. At any rate, memory
disposition etc. is not a C language matter, and is totally
off-topic here.

--
If you want to post a followup via groups.google.com, ensure
you quote enough for the article to make sense. Google is only
an interface to Usenet; it's not Usenet itself. Don't assume
your readers can, or ever will, see any previous articles.
More details at: <http://cfaj.freeshell.org/google/>
 
B

Bart van Ingen Schenau

Keith said:
(A compiler may vary this as long as any such variation has no visible
effect; for example, a declared object might not be stored anywhere if
the program never access it, or an auto object may be stored as if it
were static if the compiler can prove that the enclosing function is
never called recursively. The latter, as far as I know, is not a
likely thing for a compiler to do, since it doesn't really save time
or space.)

Actually, I have worked with a compiler which did just that.
I must admit that the compiler was not fully conforming (because
functions could not be used recursively without some extra decoration),
but the compiler would give all objects with automatic storage duration
a fixed address.
To conserve memory, would two objects that could never be alive at the
same time be allocated to overlapping memory areas.

This was a compiler for a small embedded platform (addressable memory
was 64kB)

Bart v Ingen Schenau
 

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,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top