Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > How to create separate character pointers?

Reply
Thread Tools

How to create separate character pointers?

 
 
jameskuyper@verizon.net
Guest
Posts: n/a
 
      11-09-2007
CBFalconer wrote:
> James Kuyper wrote:

....
> > I write for the current standard, not the old one. It's been many
> > years since I last worked on a system that didn't have a compiler
> > which would support at least that much of C99.

>
> /* .. */ is valid under all systems,


I restrict myself to the common subset of C90 and C99 only when
required to compile for C90 (which is true only in my work
environment). Otherwise, I write C99 code which takes full advantage
of every feature of C99 that I consider an improvement over C90.

Don't expect me to follow your coding standards, though I suppose
there's no way I can stop you from complaining when I violate them.
However, I would prefer it if you would refrain from doing so. How
would you feel if I complained every time you posted code that failed
to take advantage of C99 features that I consider to be improvements?

> ... and is immune to usenet line
> wrap.


I try to avoid posting code examples with lines long enough to wrap.
If I've failed to achieve that goal, I consider the line length to be
the problem, not the use of // comments.

 
Reply With Quote
 
 
 
 
CBFalconer
Guest
Posts: n/a
 
      11-09-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> CBFalconer wrote:
>> James Kuyper wrote:

> ...
>>> I write for the current standard, not the old one. It's been many
>>> years since I last worked on a system that didn't have a compiler
>>> which would support at least that much of C99.

>>
>> /* .. */ is valid under all systems,

>
> I restrict myself to the common subset of C90 and C99 only when
> required to compile for C90 (which is true only in my work
> environment). Otherwise, I write C99 code which takes full advantage
> of every feature of C99 that I consider an improvement over C90.
>
> Don't expect me to follow your coding standards, though I suppose
> there's no way I can stop you from complaining when I violate them.


It's not really a complaint, just intended to point out how you can
avoid nuisances in Usenet. Another point is that the receiver may
not have a compiler that accepts //. I happen to believe in
maximizing portability, barring nasty penalties.

No more need be said about it. Until I forget

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      11-09-2007
Willem wrote:
> Eric wrote:
> ) <snip>
> )> for (i = 0; i < 5; ++i)
> )> {
> )> char *str = "test";
> )> printf("%p:%s\n", str, str);
> )> }
> )
> ) Each execution of the loop creates a new `str' variable.
> ) Each time, that variable is initialized to point to the same
> ) "test" string. If your telephone number is written on five
> ) pieces of paper, it doesn't mean you have five different
> ) telephones.
>
> I bet that even if you wrote printf("%p->%p:%s\n", &str, str, str);
> that you can't find a compiler that wouldn't output the same each
> iteration, although I'm sure the Standard would allow it.


The fact that two objects share the same memory location
at different times in the program's execution does not make
them the same object.

Example 1:

char *p, *q;
p = malloc(42); /* assume success */
strcpy (p, "Zaphod");
free (p);
q = malloc(21); /* assume success */
strcpy (q, "Beeblebrox");

Even if it turns out that p and q refer (during their respective
periods of validity) to the same address, they do not refer to
the same object.

Example 2:

int f1(void) {
int i = 42;
return i;
}

int f2(void) {
int j = 24;
return j;
}

int driver(void) {
return f1() + f2();
}

Even if it turns out that i and j share the same memory location
they are different objects.

Perhaps my example of the five pieces of paper would have
been better if I'd specified that each was burned before the
next was written.

--
Eric Sosman
(E-Mail Removed)lid
 
Reply With Quote
 
Chip Coldwell
Guest
Posts: n/a
 
      11-09-2007
Lambda <(E-Mail Removed)> writes:

> I'd like to create separate character pointers,
> pass them to a function to assign each one different value,
> and assign the pointers to an array.
>
> But when I try:
>
> #include <stdio.h>
> #include <string.h>
>
> int main(void)
> {
> int i;
>
> for (i = 0; i < 5; ++i)
> {
> char *str = "test";
> printf("%p:%s\n", str, str);
> }
>
> return 0;
> }
>
> All the pointers refer to the same address.
> When the 'char *str = "test"' is run, no new pointer is created?


You are printing the value of the pointer, which is the address of the
character literal "test". If the executable were ELF formatted, this
would most likely be an address in the .rodata section.

Chip

--
Charles M. "Chip" Coldwell
"Turn on, log in, tune out"
Somerville, Massachusetts, New England
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      11-11-2007
On Nov 9, 11:17 am, (E-Mail Removed) wrote:
> CBFalconer wrote:

....
> > ... and is immune to usenet line wrap.

>
> I try to avoid posting code examples with lines long enough to wrap.


To help with that, here is a little 'Text Width Check'
tool that I offer.
<http://www.physci.org/twc.jnlp>

I recommend keeping line width to less than 62 chars for
usenet posts.

--
Andrew T.
PhySci.org

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Separate Tabs, Separate Sessions BigAndy Firefox 0 05-09-2007 09:27 AM
Separate Tabs, Separate Sessions BigAndy Firefox 0 05-09-2007 09:26 AM
Using separate classpaths for separate classes? Frank Fredstone Java 1 06-27-2006 06:46 AM
How to use several separate classes (separate files) to be executed in one class (another file) EvgueniB Java 1 12-15-2003 01:18 AM



Advertisments