Nickolai Leschov <nl******@gmail.comwrites:
I'm reading code for time function in glibc and I see the following
fragment in file time\time.h:
/* Return the time now, and store it in *TIMER if not NULL. */
time_t
time (timer)
time_t *timer;
This is an old-style (non-prototype) function declaration. Probably
either glibc still caters to ancient C compilers that don't support
prototypes, or you're looking at an old version of glibc. The modern
equivalent would be:
time_t time(time_t *timer)
{
__set_errno (ENOSYS);
This is implementation-specific. Presumably it sets errno to the
value ENOSYS, which presumably indicates that the system doesn't
support asking for the current time. (I don't know why it uses a
macro rather than just assigning a value to errno.)
if (timer != NULL)
*timer = (time_t) -1;
return (time_t) -1;
The time function, for historical reasons, returns its result in two
ways: it returns the result directly, and it stores it via the time_t*
pointer you pass in. You can avoid the latter by passing a null
pointer. This implementation of the time function always returns a
value of -1, which is used to indicate that this functionality is not
supported. (The casts are unnecessary, but if glibc supports ancient
compilers, some of them might need the casts for some reason.)
Presumably this is just the version for systems that don't support
time queries. There must be one or more other versions that return
meaningful values.
}
How do I read this function declaration?
Only the first 3 lines are a function declaration; the whole thing is
a function definition.
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"