473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Function Signatures In time.h

Hi,

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

?
Regards,

August
Apr 30 '06 #1
4 1670
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.

--
Diomidis Spinellis
Code Quality: The Open Source Perspective (Addison-Wesley 2006)
http://www.spinellis.gr/codequality?clc
Apr 30 '06 #2
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.
August
Apr 30 '06 #3
August Karlstrom <fu********@comhem.se> 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) ks***@mib.org <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.
Apr 30 '06 #4
Keith Thompson wrote:
August Karlstrom <fu********@comhem.se> 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.
[...] 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]);


You are absolutely right. In the Third Edition Unix (February 1973) the
time(2) interface is specified in assembly language: the 32-bit result
is returned in the register pair r0/r1
<http://minnie.tuhs.org/UnixTree/V3/usr/man/man2/time.2.html>. In the
Fourth Edition Unix (November 1973), which was (re)written in C, time
takes as an argument an int tvec[2]
<http://minnie.tuhs.org/UnixTree/V4/usr/man/man2/time.2.html>. Ritchie
mentions that the long type was added to C during the period 1973-1980
<http://cm.bell-labs.com/cm/cs/who/dmr/chist.html>. The long type
certainly wasn't supported by the C compiler that came with the Fifth
Edition Unix that was released on June 1974
<http://minnie.tuhs.org/UnixTree/V5/usr/c/c00.c.html>. Therefore, when
time(2) was first specified in C, an int[2] argument was a reasonable
interface specification.

--
Diomidis Spinellis
Code Quality: The Open Source Perspective (Addison-Wesley 2006)
http://www.spinellis.gr/codequality?clc
Apr 30 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: harold fellermann | last post by:
Hi all, I am trying to write a script that prints out the signatures of each function call that occurs during the execution of a second script which is invoked by my program. i.e. if the...
4
by: Alex Vinokur | last post by:
Hi, I need something like "function inheritance". typedef void (*func_type1) (int); typedef int (*func_type2) (double); typedef char (*func_type3) (short, int); .... I need a vector...
4
by: Calum | last post by:
I need to call a function in a shared library, but the type of the function is not known until run-time. enum Type { Void=0, Char, Uchar, Short, Ushort, Int, Uint, Float, Double, String }; ...
5
by: Rolf Wester | last post by:
Hi, I want to pass a C-function as a function parameter but I don't know how to that correctly. In the example below how would I have to declare the function argument in the my_sort function...
3
by: Randy Yates | last post by:
Hi, We know we can build arrays of variables of the same type and arrays of functions of the same "type" (i.e., same return value and same parameters), but is there a way to automate the calling...
4
by: Alfonso Morra | last post by:
I have come accross some code where function pointers are being cast from one type to another (admittedly, they all have the same return type). eg. you may have func ptrs declr as ff: typedef...
6
by: Matt Frame | last post by:
I have a client that has asked us to get a digital signature certificate and start digitally signing all files we pass between each other. I have heard of the subject and know about the certs but...
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
83
by: Anonymous | last post by:
Came across some code summarized as follows: char const* MyClass::errToText(int err) const { switch (err) { case 0: return "No error"; case 1: return "Not enough"; case 2: return "Too...
0
digicrowd
by: digicrowd | last post by:
http://bytes.com/images/howtos/applemail_sig_icon.jpg At first glance, it may not appear that Apple Mail (otherwise known as Mail.app) supports the use of HTML signature emails. However, with a...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.