C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

regarding command line arguments

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C Language (Moderated)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Thu Mar 29, 2007 6:26 am    Post subject: regarding command line arguments Reply with quote



Hi All,

Can somebody help me by answering this question?
This is regarding the command line arguments that are passed to the
main() in C.
For the commands line parameters that are passed by the user, will the
memory for them be allocated on the stack or heap?

For instance, Consider the below code snippet that prints the command
line arguments:

int main(int argc, char *argv[])
{
int x;

printf("%d\n",argc);
for (x=0; x<argc; x++)
printf("%s\n",argv[x]);
return 0;
}

If I execute this program:

testPrg arg1 arg2 arg3

Then the memory for the command line arguments (arg1, arg2, arg3) be
allocated on the program stack or the heap memory.

Thanks in advance.

Warm Regards.
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Hans-Bernhard Bröker
Guest





PostPosted: Mon Apr 16, 2007 8:18 pm    Post subject: Re: regarding command line arguments Reply with quote



sk.smawsk (AT) gmail (DOT) com wrote:

Quote:
For the commands line parameters that are passed by the user, will the
memory for them be allocated on the stack or heap?

Actually that's none of your business to know. They exist as long as
you need them, period.

And that's before we consider that there's not even any guarantee that
such a thing as a "stack" even exists, in Standard C.
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
WillerZ
Guest





PostPosted: Mon Apr 16, 2007 8:18 pm    Post subject: Re: regarding command line arguments Reply with quote



sk.smawsk (AT) gmail (DOT) com wrote:
Quote:
Hi All,

Can somebody help me by answering this question?
This is regarding the command line arguments that are passed to the
main() in C.
For the commands line parameters that are passed by the user, will the
memory for them be allocated on the stack or heap?

Not necessarily.
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Gordon Burditt
Guest





PostPosted: Mon Apr 16, 2007 8:18 pm    Post subject: Re: regarding command line arguments Reply with quote

Quote:
Can somebody help me by answering this question?
This is regarding the command line arguments that are passed to the
main() in C.
For the commands line parameters that are passed by the user, will the
memory for them be allocated on the stack or heap?

Possibly not.

The C standard doesn't define these terms, so I'm using these
definitions:

Stack: That place from which memory allocated by malloc() and friends
comes from. (e.g. Motorola, Samsung, or Texas Instruments)
Heap: That place from which memory for automatic variables comes from.
Nothing in these definitions prohibit both from taking memory from the
SAME place.

You must not free() the command-line arguments; the penalty is undefined
behavior. Also, the command-line arguments don't vanish when a function
returns. NEITHER of these places seems appropriate.

Quote:
For instance, Consider the below code snippet that prints the command
line arguments:

int main(int argc, char *argv[])
{
int x;

printf("%d\n",argc);
for (x=0; x<argc; x++)
printf("%s\n",argv[x]);
return 0;
}

If I execute this program:

testPrg arg1 arg2 arg3

Then the memory for the command line arguments (arg1, arg2, arg3) be
allocated on the program stack or the heap memory.

Not necessarily.
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Thomas Richter
Guest





PostPosted: Mon Apr 16, 2007 8:18 pm    Post subject: Re: regarding command line arguments Reply with quote

sk.smawsk (AT) gmail (DOT) com wrote:

Quote:
int main(int argc, char *argv[])
{
int x;

printf("%d\n",argc);
for (x=0; x<argc; x++)
printf("%s\n",argv[x]);
return 0;
}

If I execute this program:

testPrg arg1 arg2 arg3

Then the memory for the command line arguments (arg1, arg2, arg3) be
allocated on the program stack or the heap memory.

Wherever the compiler choose to put them. As you don't have to release
the memory for the arguments, its not your matter to know where the
memory has been taken from.

So long,
Thomas
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Jonas
Guest





PostPosted: Mon Apr 16, 2007 8:18 pm    Post subject: Re: regarding command line arguments Reply with quote

<sk.smawsk (AT) gmail (DOT) com> wrote in message
news:clcm-20070328-0012 (AT) plethora (DOT) net...
Quote:
Hi All,

Can somebody help me by answering this question?
This is regarding the command line arguments that are passed to the
main() in C.
For the commands line parameters that are passed by the user, will the
memory for them be allocated on the stack or heap?

For instance, Consider the below code snippet that prints the command
line arguments:

int main(int argc, char *argv[])
{
int x;

printf("%d\n",argc);
for (x=0; x<argc; x++)
printf("%s\n",argv[x]);
return 0;
}

If I execute this program:

testPrg arg1 arg2 arg3

Then the memory for the command line arguments (arg1, arg2, arg3) be
allocated on the program stack or the heap memory.


The layout of storage for parameters is unspecified behavior.

Jonas
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Siddhartha Gandhi
Guest





PostPosted: Mon Apr 16, 2007 8:19 pm    Post subject: Re: regarding command line arguments Reply with quote

On Mar 28, 9:26 pm, sk.sma...@gmail.com wrote:
Quote:
Hi All,

Can somebody help me by answering this question?
This is regarding the command line arguments that are passed to the
main() in C.
For the commands line parameters that are passed by the user, will the
memory for them be allocated on the stack or heap?

For instance, Consider the below code snippet that prints the command
line arguments:

int main(int argc, char *argv[])
{
int x;

printf("%d\n",argc);
for (x=0; x<argc; x++)
printf("%s\n",argv[x]);
return 0;

}

If I execute this program:

testPrg arg1 arg2 arg3

Then the memory for the command line arguments (arg1, arg2, arg3) be
allocated on the program stack or the heap memory.

Thanks in advance.

Warm Regards.
--
comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.

Don't quote me on this, but I'd say stack.
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Jonathan Leffler
Guest





PostPosted: Mon Apr 16, 2007 8:19 pm    Post subject: Re: regarding command line arguments Reply with quote

sk.smawsk (AT) gmail (DOT) com wrote:
Quote:
This is regarding the command line arguments that are passed to the
main() in C.
For the commands line parameters that are passed by the user, will the
memory for them be allocated on the stack or heap?
[...]
Then the memory for the command line arguments (arg1, arg2, arg3) be
allocated on the program stack or the heap memory.

You can't tell. You don't need to know. It makes no difference to what
you can do - beyond, perhaps, noting that you cannot safely use free()
on the argument strings or the array of pointers to those strings. The
standard does not say. It might be in neither - it/they could be
stashed alongside the global variables (unlikely, but not ruled out by
the standard).


--
Jonathan Leffler #include <disclaimer.h>
Email: jleffler (AT) earthlink (DOT) net, jleffler (AT) us (DOT) ibm.com
Guardian of DBD::Informix v2007.0226 -- http://dbi.perl.org/
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Douglas A. Gwyn
Guest





PostPosted: Thu Apr 19, 2007 7:13 pm    Post subject: Re: regarding command line arguments Reply with quote

Gordon Burditt wrote:
Quote:
The C standard doesn't define these terms, so I'm using these
definitions:
Stack: That place from which memory allocated by malloc() and friends
comes from. (e.g. Motorola, Samsung, or Texas Instruments)
Heap: That place from which memory for automatic variables comes from.

That's contrary to established usage.
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Douglas A. Gwyn
Guest





PostPosted: Thu Apr 19, 2007 7:13 pm    Post subject: Re: regarding command line arguments Reply with quote

Hans-Bernhard Bröker wrote:
Quote:
... there's not even any guarantee that
such a thing as a "stack" even exists, in Standard C.

However, there have to be procedure activation records
that are used according to a stack discipline (which
longjmp intentionally violates).
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Kenneth Brody
Guest





PostPosted: Fri Apr 20, 2007 4:25 am    Post subject: Re: regarding command line arguments Reply with quote

Martin Ambuhl wrote:
Quote:

Gordon Burditt wrote:
Can somebody help me by answering this question?

The C standard doesn't define these terms, so I'm using these
definitions:

Stack: That place from which memory allocated by malloc() and friends
comes from. (e.g. Motorola, Samsung, or Texas Instruments)
Heap: That place from which memory for automatic variables comes from.
Nothing in these definitions prohibit both from taking memory from the
SAME place.

It is perhaps worthwhile, although off-topic, to note that this is just
the reverse of what most implementations that use the terms "stack" and
"heap" use them to mean.
[...]


This may have been intentional. Because the standard doesn't define
those terms, you are free to define them as you see fit, and you can't
say his definitions as "wrong", just as you could define "sockets" as
"Secure Operations Cluster-Kill Extended Targeting Solutions" and not
be "wrong" as far as the C standard is concerned.

On the other hand, it may have simply been a brain fart.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:ThisIsASpamTrap (AT) gmail (DOT) com>
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Martin Ambuhl
Guest





PostPosted: Sat Apr 21, 2007 5:15 pm    Post subject: Re: regarding command line arguments Reply with quote

Kenneth Brody wrote:
Quote:
Martin Ambuhl wrote:
Gordon Burditt wrote:
Can somebody help me by answering this question?
The C standard doesn't define these terms, so I'm using these
definitions:

Stack: That place from which memory allocated by malloc() and friends
comes from. (e.g. Motorola, Samsung, or Texas Instruments)
Heap: That place from which memory for automatic variables comes from.
Nothing in these definitions prohibit both from taking memory from the
SAME place.
It is perhaps worthwhile, although off-topic, to note that this is just
the reverse of what most implementations that use the terms "stack" and
"heap" use them to mean.
[...]

This may have been intentional. Because the standard doesn't define
those terms, you are free to define them as you see fit, and you can't
say his definitions as "wrong",

And I do not say his definitions are [not "as"] wrong. I worte that
they are the reverse of normal usage. I make no attempt to "correct" him.

Quote:
just as you could define "sockets" as
"Secure Operations Cluster-Kill Extended Targeting Solutions" and not
be "wrong" as far as the C standard is concerned.

On the other hand, it may have simply been a brain fart.

--

comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Mark L Pappin
Guest





PostPosted: Sat Apr 21, 2007 5:15 pm    Post subject: Re: regarding command line arguments Reply with quote

"Douglas A. Gwyn" <DAGwyn (AT) null (DOT) net> writes:
Quote:
Gordon Burditt wrote:

(Now, Gordon, if I hadn't included these attributions, and someone saw
only this posting, they wouldn't know the original wisdom was yours.)

Quote:
The C standard doesn't define these terms, so I'm using these
definitions:
Stack: That place from which memory allocated by malloc() and friends
comes from. (e.g. Motorola, Samsung, or Texas Instruments)
Heap: That place from which memory for automatic variables comes from.

That's contrary to established usage.

That's almost certainly his point: "established usage" still isn't
necessarily part of the language. The only guaranteed references here
are the C standard [pick a version] and the English language. Since
"stack" and "heap" are not defined in the former, and are generally
synonyms in the latter (although with connotations of order and
disorder respectively), if the [unquoted] OP mentions them we are
entitled to define them any way we want - they're not part of C.

Gordon stated up front the definitions he was using above and beyond
those guaranteed by the standard, and proceded to answer the OP's
question using those definitions. He also noted other salient facts
that might be of use to the OP.

mlp
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Keith Thompson
Guest





PostPosted: Mon Apr 23, 2007 10:59 pm    Post subject: Re: regarding command line arguments Reply with quote

Mark L Pappin <mlp (AT) acm (DOT) org> writes:
Quote:
"Douglas A. Gwyn" <DAGwyn (AT) null (DOT) net> writes:
Gordon Burditt wrote:

(Now, Gordon, if I hadn't included these attributions, and someone saw
only this posting, they wouldn't know the original wisdom was yours.)

The C standard doesn't define these terms, so I'm using these
definitions:
Stack: That place from which memory allocated by malloc() and friends
comes from. (e.g. Motorola, Samsung, or Texas Instruments)
Heap: That place from which memory for automatic variables comes from.

That's contrary to established usage.

That's almost certainly his point: "established usage" still isn't
necessarily part of the language. The only guaranteed references here
are the C standard [pick a version] and the English language. Since
"stack" and "heap" are not defined in the former, and are generally
synonyms in the latter (although with connotations of order and
disorder respectively), if the [unquoted] OP mentions them we are
entitled to define them any way we want - they're not part of C.

Gordon stated up front the definitions he was using above and beyond
those guaranteed by the standard, and proceded to answer the OP's
question using those definitions. He also noted other salient facts
that might be of use to the OP.

In technical English, used when discussing computer programming, the
terms "stack" and "heap" are definitely not synonyms.

--
Keith Thompson (The_Other_Keith) kst-u (AT) mib (DOT) org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Douglas A. Gwyn
Guest





PostPosted: Mon Apr 23, 2007 10:59 pm    Post subject: Re: regarding command line arguments Reply with quote

"Mark L Pappin" <mlp (AT) acm (DOT) org> wrote in message
news:clcm-20070421-0002 (AT) plethora (DOT) net...
Quote:
"Douglas A. Gwyn" <DAGwyn (AT) null (DOT) net> writes:
That's contrary to established usage.
That's almost certainly his point: "established usage" still isn't
necessarily part of the language. The only guaranteed references here
are the C standard [pick a version] and the English language. Since
"stack" and "heap" are not defined in the former, and are generally
synonyms in the latter (although with connotations of order and
disorder respectively), if the [unquoted] OP mentions them we are
entitled to define them any way we want - they're not part of C.

No, that's nonsense. The C standard does not, and does not have to,
define a great number of terms (which are taken to have their usual
meanings; there is even reference to a standard dictionary for IT terms).
But even more to the point, a questioner can use common terms in his
question, whether or not the terms are found in the C standard.
In this particular case, it was appropriate to point out that the standard
does not require either a stack or a heap storage discipline for the
command-line argument array. It may even be worth mentioning that
those are informal terms and that the standard uses different formal
language concerning such matters. It s not appropriate to define the
terms contrary to established usage.
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.