C question...little OT

M

mdh

May I ask something that has often puzzled me in C.
In K&R, for example (p106), in explaining their version of strcmp,
pointers to the two strings are given as *s and *t.
Does anyone know how this convention started. Does the "s" stand for
"source" string, for example. Or is it as simple as s="string",
i="integer" and the next string would be t, u, v, etc.
Thanks
 
R

Richard Heathfield

mdh said:
May I ask something that has often puzzled me in C.
In K&R, for example (p106), in explaining their version of strcmp,
pointers to the two strings are given as *s and *t.
Does anyone know how this convention started. Does the "s" stand for
"source" string, for example.

I hope not, because that's not the source - it's the target!
Or is it as simple as s="string",
i="integer" and the next string would be t, u, v, etc.

Yeah, I think that's the most likely explanation. Certainly, when I
demonstrate strcpy, I use char *u = s to hold the return value.
 
M

mdh

....... two strings are given as *s and *t.
I hope not, because that's not the source - it's the target!
Yeah, I think that's the most likely explanation. Certainly, when I
demonstrate strcpy, I use char *u = s to hold the return value.

tks Richard.
 
P

pete

Roland said:
To wit, real gurus use one-letter names.

Which means that the standard's description of string.h
was written by gurus,
and that the standard's description of stdlib.h
was written by neophytes.

void *memset(void *s, int c, size_t n;

void *bsearch(const void *key, const void *base,
size_t nmemb, size_t size,
int (*compar)(const void *, const void *));

Either that, or your comment is silly.
 
C

Chris Hills

Richard Heathfield said:
Roland Pibinger said:


Only when it's obvious what they're for, as in this case.

Stroustrup once suggested that [now we have unicode] function names
should all be one character but have a different colour to indicate
their use. So you could have 256 functions called A() :)
 
M

mdh

Stroustrup once suggested that [now we have unicode] function names
should all be one character but have a different colour to indicate
their use. So you could have 256 functions called A() :)

oh..great!! That's all I need!!! :)
 
C

Chris Hills

mdh said:
Stroustrup once suggested that [now we have unicode] function names
should all be one character but have a different colour to indicate
their use. So you could have 256 functions called A() :)

oh..great!! That's all I need!!! :)

Caveat: It was after mid-night in a restaurant and there was a lot of
beer about :)
 
C

CBFalconer

mdh said:
May I ask something that has often puzzled me in C.
In K&R, for example (p106), in explaining their version of strcmp,
pointers to the two strings are given as *s and *t.
Does anyone know how this convention started. Does the "s" stand for
"source" string, for example. Or is it as simple as s="string",
i="integer" and the next string would be t, u, v, etc.

They are just labels, and only valid within the function. There is
no special meaning. Change them if you like, you won't affect the
code (but maybe the debugging info).
 
C

CBFalconer

Chris said:
Chris Hills said:
Stroustrup once suggested that [now we have unicode] function
names should all be one character but have a different colour to
indicate their use. So you could have 256 functions called A() :)

oh..great!! That's all I need!!! :)

Caveat: It was after mid-night in a restaurant and there was a
lot of beer about :)

Making programming unavailable to the color-blind. Whee.
 
A

Army1987

Richard Heathfield said:
Roland Pibinger said:


Only when it's obvious what they're for, as in this case.

Not very much, I'd call them char *to and const char *from, or
source and dest...
It is not obvious that strcpy(s, t) copies t into s rather than
viceversa (until you learn the "it mimicks the order which would be
used in an assignment s = t" mnemonic).
(But when looking at the prototype, the fact that one points to
char and the other to const char makes it clear.)
 
A

Army1987

Chris Hills said:
Roland Pibinger said:


Only when it's obvious what they're for, as in this case.

Stroustrup once suggested that [now we have unicode] function names should all be one character but have a different colour to
indicate their use. So you could have 256 functions called A() :)

In maths, you can't use several letters for a name (ab would mean
a times b), but there are plenty of capital letters, greek letters,
strange diacritics, subscripts etc. to have enough symbols. But I
once resorted to use a cyrillic l for a length when I was already
using L, l and a greek lambda in the problem.
 
L

lawrence.jones

pete said:
Which means that the standard's description of string.h
was written by gurus,
and that the standard's description of stdlib.h
was written by neophytes.

That's probably closer to the truth than you ever imagined. (Most of
the standard's function definitions, including the parameter names, came
from existing library documentation, most of which in turn came from
existing library implementations.)

-Larry Jones

I keep forgetting that rules are only for little nice people. -- Calvin
 
R

Richard Bos

Chris Hills said:
Richard Heathfield said:
Roland Pibinger said:


Only when it's obvious what they're for, as in this case.

Stroustrup once suggested that [now we have unicode] function names
should all be one character but have a different colour to indicate
their use. So you could have 256 functions called A() :)

I strongly doubt that. Stroustrup is not a fool (for all that he
designed C++ ;-) ) and he is certainly not stupid enough to confuse
character sets with colour.

Richard
 
C

Chris Hills

Richard Bos said:
Chris Hills said:
Richard Heathfield said:
Roland Pibinger said:

May I ask something that has often puzzled me in C.
In K&R, for example (p106), in explaining their version of strcmp,
pointers to the two strings are given as *s and *t.
Certainly, when I
demonstrate strcpy, I use char *u = s to hold the return value.

To wit, real gurus use one-letter names.

Only when it's obvious what they're for, as in this case.

Stroustrup once suggested that [now we have unicode] function names
should all be one character but have a different colour to indicate
their use. So you could have 256 functions called A() :)

I strongly doubt that.

I was there when he said it. However did you miss the caveat?
Stroustrup is not a fool (for all that he
designed C++ ;-) ) and he is certainly not stupid enough to confuse
character sets with colour.

You had to have been there really.
 
B

bjarne

Stroustrup once suggested that [now we have unicode] function names
should all be one character but have a different colour to indicate
their use. So you could have 256 functions called A() :)
I strongly doubt that.

I was there when he said it. However did you miss the caveat?
Stroustrupis not a fool (for all that he
designed C++ ;-) ) and he is certainly not stupid enough to confuse
character sets with colour.

You had to have been there really.

B Stroustrup: Generalizing Overloading for C++2000. Overload, Issue
25. April 1, 1998. Note the date. http://www.research.att.com/~bs/whitespace98.pdf

-- Bjarne Stroustrup; http://www.research.att.com/~bs
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top