From: Mohammed Khalid Ansari <khalid@ncst.ernet.in>
To: Glynn Clements <glynn.clements@virgin.net>
Cc: Alvarez Alberto-AALVARB1 <AALVARB1@motorola.com>,
linux c programming mailing list
<linux-c-programming@vger.kernel.org>
Subject: RE: strange behavious
Date: Wed, 25 Dec 2002 18:01:52 +0530 (IST) [thread overview]
Message-ID: <Pine.LNX.4.33.0212251759050.11856-100000@soochak.ncst.ernet.in> (raw)
In-Reply-To: <15881.32906.386882.764352@cerise.nosuchdomain.co.uk>
On Wed, 25 Dec 2002, Glynn Clements wrote:
>
> Mohammed Khalid Ansari wrote:
>
> > > i'll try to answer your question. This may be not be an accurate answer, but i think it'll do.
> > >
> > > The way you've assigned values to 'words' is the reason of the failure. The allocation of memory takes place in program data space (the same place where code is), so you can't modify it.
> > > If you want to modify that array, you should dynamically allocate it. Something like this will work,
> >
> > that means it should not work for the following code as the memory is
> > allocated in program data space, but it works...
> >
> > #######
> > #include <stdio.h>
> >
> > int main()
> > {
> > char string[] = "mohammed";
> >
> > strcpy (string, "khalid");
> > printf ("%s\n", string);
> >
> > return 0;
> > }
> > #######
>
> Sure; in this case the variable "string" is stored in the data
> segment, which is mutable.
>
>
The above above answer by Mr Alvarez Alberto-AALVARB1 says that since the
array words is stored in program data space which is not modifiable and
therefore I get segmentation fault. While here I have given an example of
modifiable string and you say that since string is stored in the data
segment, it is modifiable. Please clarify.
with regards...
next prev parent reply other threads:[~2002-12-25 12:31 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-12-23 8:27 strange behavious Alvarez Alberto-AALVARB1
2002-12-24 5:15 ` Mohammed Khalid Ansari
2002-12-25 9:55 ` Glynn Clements
2002-12-25 12:31 ` Mohammed Khalid Ansari [this message]
2002-12-25 13:44 ` Glynn Clements
-- strict thread matches above, loose matches on Subject: below --
2002-12-21 5:25 Mohammed Khalid Ansari
2002-12-23 8:19 ` Glynn Clements
2002-12-24 5:20 ` Mohammed Khalid Ansari
2002-12-25 9:50 ` Glynn Clements
[not found] ` <Pine.LNX.4.33.0212241046350.31854-100000@soochak.ncst.erne t.in>
2002-12-24 10:12 ` Stephen Satchell
2002-12-25 12:28 ` Mohammed Khalid Ansari
2002-12-25 13:58 ` Glynn Clements
[not found] ` <Pine.LNX.4.33.0212251757430.11856-100000@soochak.ncst.erne t.in>
2002-12-25 21:39 ` Stephen Satchell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.33.0212251759050.11856-100000@soochak.ncst.ernet.in \
--to=khalid@ncst.ernet.in \
--cc=AALVARB1@motorola.com \
--cc=glynn.clements@virgin.net \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).