The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [TUHS] C declarations.
@ 2017-05-11 21:49 Ron Natalie
  2017-05-11 22:01 ` Arthur Krewat
  2017-05-11 22:03 ` David Arnold
  0 siblings, 2 replies; 48+ messages in thread
From: Ron Natalie @ 2017-05-11 21:49 UTC (permalink / raw)


Bjarne agrees with you.   He put the * (and the &) with the type name to emphasize it is part of the type.
This works fine as long as you only use one declaration per statement.

The problem with that is that * doesn't really bind to the type name.   It binds to the variable.

char* cp1, cp2;   // cp1 is pointer to char,   cp2 is just a char.

I always found it confusing that the * is used to indicate an pointer here, where as when you want to change an lvalue to a pointer, you use &.

But if we're going to gripe about the evolution of C.   My biggest gripe is when they fixed structs to be real types, they didn't also do so for arrays.
Arrays and their  degeneration to poitners is one of the biggest annoyances in C.

> Am I the only one here who thinks that e.g. a char pointer should be
> "char* cp1, cp2" instead of "char *cp1, *cp2"?  I.e. the fundamental type is "char*", not "char", and to this day I still write:




^ permalink raw reply	[flat|nested] 48+ messages in thread
* [TUHS] C declarations.
@ 2017-05-12 14:04 Richard Tobin
  0 siblings, 0 replies; 48+ messages in thread
From: Richard Tobin @ 2017-05-12 14:04 UTC (permalink / raw)


> The problem with that is that * doesn't really bind to the type name. 
> It binds to the variable.
> 
> char* cp1, cp2;   // cp1 is pointer to char,   cp2 is just a char.
> 
> I always found it confusing that the * is used to indicate an pointer
> here, where as when you want to change an lvalue to a pointer, you use
> &.

The way to read it is that you are declaring *cp1 as a char.

-- Richard

-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.



^ permalink raw reply	[flat|nested] 48+ messages in thread
* [TUHS] C declarations.
@ 2017-05-13 23:11 Richard Tobin
  2017-05-15  6:46 ` Tim Bradshaw
  0 siblings, 1 reply; 48+ messages in thread
From: Richard Tobin @ 2017-05-13 23:11 UTC (permalink / raw)


> Fortran, for the record, passes nearly everything by reference

Sort of.  The Fortran 77 standard imposes restrictions that appear to
be intended to allow the implementation to pass by value-and-result
(i.e. values are copied in, and copied back at return).  In particular
it disallows aliasing that would allow you to distinguish between
the two methods:

  If a subprogram reference causes a dummy argument in the referenced
  subprogram to become associated with another dummy argument in the
  referenced subprogram, neither dummy argument may become defined
  during execution of that subprogram.

http://www.fortran.com/F77_std/rjcnf-15.html#sh-15.9.3.6

-- Richard

-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.



^ permalink raw reply	[flat|nested] 48+ messages in thread
* [TUHS] C declarations.
@ 2017-05-14 14:11 Doug McIlroy
  2017-05-14 14:58 ` Steve Nickolas
  0 siblings, 1 reply; 48+ messages in thread
From: Doug McIlroy @ 2017-05-14 14:11 UTC (permalink / raw)


> Are there languages that copy arrays in function calls defaultly?

> Pascal is an example.

Pascal's var convention, where the distinction between value
and reference is made once and for all for each argument of
each function, is sound. The flexibility of PL/I, where the
distinction is made at every call (parenthesize the name to
pass an array by value) is finicky, though utterly general.

> Where is all that [memory]  going to come from if you pass a
> large array on a memory-constrained system of specs common back in the
> days when C was designed

Amusingly, under the customary linkage method in the even earlier
days when Fortran was designed, pass-by-reference entailed a big
overhead that could easily dominate pass-by-value for small arrays.

[In the beginning, when CPUs had only one register, subroutine
preambles plugged the reference into every mention of that variable
throughout the body of the subroutine. This convention persisted
in Fortran, which was designed for a machine with three index
registered. Since reference variables were sometimes necessary
(think of swap(a,b) for example) they were made standard.] 

Doug


^ permalink raw reply	[flat|nested] 48+ messages in thread
* [TUHS] C declarations.
@ 2017-05-15 18:47 Steve Johnson
  2017-05-15 19:54 ` Bakul Shah
  2017-05-16  7:25 ` George Ross
  0 siblings, 2 replies; 48+ messages in thread
From: Steve Johnson @ 2017-05-15 18:47 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2633 bytes --]



	Some interesting comments:

	    "You all are missing the point as to what the cost of passing
arrays by value or what other languages do"

	I don't think so.  To me the issues is that the model of what it
means to compute has changed since the punch-card days.  When you
submitted a card deck in the early days, you had to include both the
function definition and the data--the function was compiled, the data
was read, and, for the most part there were no significant side
effects (just a printout, and maybe some stuff on mag tape).

	This was a model that had served mathematics well for centuries, and
it was very easy to understand.  Functional programming people still
like it a lot...

	However, with the introduction of permanent file systems, a new
paradigm came into being.  Now, interactions with the computer looked
more like database transactions:  Load your program, change a few
lines, put it back, and then call 'make'.  Trying to describe this
with a purely functional model leads to absurdities like:

	     file_system = edit( file_system, file_selector,
editing_commands );

	In fact, the editing commands can change files, create new ones, and
even delete files.  There is no reasonable way to handle any
realistic file systems with this model (let alone the Internet!)

	In C's early days, we were just getting into the new world.  Call by
value for arrays would have been expensive or impossible on the
machine with just a few kilobytes of memory for program + data.  So
we didn't do it.

	Structures were initially handled like arrays, but the compiler chose
to make a local copy when passed a structure pointer.  This copy was,
at one time, in static memory, which caused some problems.  Later, it
went on the stack.  It wasn't much used...

	This changed when the Blit terminal project was in place.  It was
just too attractive on a 68000 to write

	    struct pt = {  int x;  int y }        /* when int was
16-bits */

	and I made PCC pass small structures like this in registers, like
other arguments.  I seem to remember a dramatic speedup (2X or so)
from doing this...

"(did) Dennis / Brian/ Ken regret this design choice?

	Not that I recall.  Of course, we all had bugs in this area.  But I
think the lack of subscript range checking was a more serious problem
than using pointers in the first place.  And, indeed, for a few of
the pioneers, BCPL had done exactly the same thing.  

	Steve


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20170515/3b53b088/attachment.html>


^ permalink raw reply	[flat|nested] 48+ messages in thread

end of thread, other threads:[~2017-05-16  7:25 UTC | newest]

Thread overview: 48+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-11 21:49 [TUHS] C declarations Ron Natalie
2017-05-11 22:01 ` Arthur Krewat
2017-05-11 23:44   ` Dave Horsfall
2017-05-11 22:03 ` David Arnold
2017-05-11 22:32   ` Larry McVoy
2017-05-11 22:41     ` Ron Natalie
2017-05-13  1:24       ` Larry McVoy
2017-05-13  2:45         ` Ron Natalie
2017-05-13 12:20           ` Michael Kjörling
2017-05-13 12:35             ` Tim Bradshaw
2017-05-13 12:42               ` Michael Kjörling
2017-05-13 15:36                 ` Stephen Kitt
2017-05-14  1:59                 ` Lawrence Stewart
2017-05-14  2:23                   ` Dave Horsfall
2017-05-14  4:24                   ` Bakul Shah
2017-05-14  6:12                     ` Steve Johnson
2017-05-14  6:48                       ` Bakul Shah
2017-05-14 23:06                         ` Ron Natalie
2017-05-14 23:34                           ` Arthur Krewat
2017-05-15  0:14                             ` Dan Cross
2017-05-15  0:23                               ` Ron Natalie
2017-05-15  3:43                                 ` Random832
2017-05-15  0:40                               ` Larry McVoy
2017-05-15  2:00                                 ` Nevin Liber
2017-05-15 10:21                                 ` Tony Finch
2017-05-15  4:35                     ` Dave Horsfall
2017-05-15  4:54                       ` Bakul Shah
2017-05-15  5:01                         ` Dave Horsfall
2017-05-15 12:58                       ` Michael Kjörling
2017-05-15 16:58                         ` Dave Horsfall
2017-05-15 19:00                           ` [TUHS] cdecl (Re: " Bakul Shah
2017-05-15 22:52                             ` Dave Horsfall
2017-05-13 13:46               ` [TUHS] " Hellwig Geisse
2017-05-13 19:08               ` Random832
2017-05-13 23:21                 ` Dave Horsfall
2017-05-14 14:48                   ` Nemo
2017-05-13 19:05             ` Random832
2017-05-14 13:14               ` Derek Fawcus
2017-05-12  0:15     ` Bakul Shah
2017-05-12  2:41       ` Theo Pavlidis
2017-05-12 14:04 Richard Tobin
2017-05-13 23:11 Richard Tobin
2017-05-15  6:46 ` Tim Bradshaw
2017-05-14 14:11 Doug McIlroy
2017-05-14 14:58 ` Steve Nickolas
2017-05-15 18:47 Steve Johnson
2017-05-15 19:54 ` Bakul Shah
2017-05-16  7:25 ` George Ross

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).