Re: Function Signatures In time.h



August Karlstrom <fusionfive@xxxxxxxxx> writes:
Diomidis Spinellis wrote:
August Karlstrom wrote:

Does anyone know why some of the functions in time.h use pointers
to constant objects of type time_t when time_t is an aritmetic
type. Why is e.g. ctime declared as

char* ctime(const time_t* tp);

and not as

char* ctime(time_t t);
My guess is that this is an implementation decision related to the
environment where C has its roots. In the Seventh Edition Unix (and
probably also in earlier versions), time_t is implemented as a long
<http://minnie.tuhs.org/UnixTree/V7/usr/include/sys/types.h.html>.
On a PDP-11 where that 1979 version of Unix run, passing as an
argument a 16 bit pointer to a 32 bit long was probably more
efficient than passing the actual 32 bit value.

OK, thanks for the input. On the other hand, the function difftime

double difftime(time_t t2, time_t t1);

does not use pointer arguments.

Probably difftime() wasn't added until later.

I *think* that on some early implementations, 32-bit ints weren't
directly supported, and what's now a ftime_t was probably defined as
an array of two ints. The declaration of time() may have been
something like:

time(int t[2]);

Certainly much of the C library would be different if it were being
defined from scratch today, without concern for backward
compatibility.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.



Relevant Pages

  • Re: Static memory overrun help
    ... > passing it a pointer to one int, and you overflow bounds by ... > writing 100 ints to that pointer). ... Since there are 100 ints at that address, ...
    (comp.lang.cpp)
  • Re: [PATCH] [0/9] Use 64bit x86 machine check code for 32bit too
    ... warning: passing argument 2 of ‘strict_strtoull’ makes integer from pointer without a cast ...
    (Linux-Kernel)
  • Re: question about pointer define
    ... p is a pointer to an array of 3 ints. ... Note that we considered this conversion rule in two different ...
    (comp.lang.c)
  • Re: ByVal vs. ByRef
    ... But I still don't understand why I have to pass the TreeNode argument ByVal. ... I understand why passing it ByVal works. ... What is "the Value" of a reference variable? ... A "pointer" to the object. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Can a ref parameter be saved for later use?
    ... but in this scenario the 'passing back' will have to happen later. ... Form(ref string[] strLst) { ... Even in C/C++ it's a dangerous thing to capture a pointer to some data and save it for reuse later. ...
    (microsoft.public.dotnet.languages.csharp)