| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: [C] Question about e |
From: Bob Stout
On 26 Jan 2004 Neil.Heller!1.106.2000.0{at}filegate.net wrote:
> LP>Well... I understand what you're saying, and apparently
> LP>I've missed something (doh!) in my understanding of this.
> LP>I'm aware that I can't, e.g.,
>
> LP>char text[12];
> LP>text = "Some text";
Right, but you can do:
char text[12];
strcpy(text, "Some text");
> You can, however, do
>
> char text = "Some text";
>
> Don't try to change text.
Actually, changing `text' is perfectly OK. All that will happen is that the
char pointer, `text' will now point to a different literal array. The
problem comes if you want to have it continue to point to the same original
storage location and change its contents.
> LP>Instead, I have to strcpy or similar to assign it. What I
> LP>was thinking that when I create a pointer to char, I can
> LP>effectively point it at a string literal I've created.
>
> That's not defined in the C standard. It may work with one compiler
> (Borland) and not with another (Microsoft).
True, array initializers may live in ROM or other non-volatile memory, so
you can't count on being able to modify them. OTOH, in many hosted
environments (e.g. PC's), the initializers probably live in RAM, loaded
along with the rest of the program. In that case, the OS and compiler work
together to determine whether you have write access to it. A typical
multi-user OS would say no.
-------------------------------------------------------------
Consulting: http://www.MicroFirm.biz/ Web graphics development:
http://Image-Magicians.com/ Software archives:
http://snippets.snippets.org/
c.snippets.org/ cpp.snippets.org/ java.snippets.org/
d.snippets.org/ python.snippets.org/ perl.snippets.org/
dos.snippets.org/ embedded.snippets.org/ apps.snippets.org/
Audio and loudspeaker design:
http://LDSG.snippets.org/ http://www.diyspeakers.net/
--- BBBS/LiI v4.01 Flag-5
* Origin: Prism's_Point (1:261/38.1)SEEN-BY: 633/267 270 @PATH: 261/38 123/500 106/2000 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.