473,405 Members | 2,287 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,405 software developers and data experts.

code in time\time.h in glibc-2.7

Hello,

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;
{
__set_errno (ENOSYS);

if (timer != NULL)
*timer = (time_t) -1;
return (time_t) -1;
}

How do I read this function declaration?

Nickolai
Oct 15 '08 #1
5 2906
Nickolai Leschov said:
Hello,

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

That's very old C - it's called "K&R style", and nobody uses it any more.
Nowadays, we'd write this as:

time_t time(time_t *timer)
{

This newer form (which is now a couple of decades old!) is known as a
"prototype", and is intended to give the compiler greater scope for
type-checking.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Oct 15 '08 #2
Nickolai Leschov wrote:
Hello,

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;
{
__set_errno (ENOSYS);

if (timer != NULL)
*timer = (time_t) -1;
return (time_t) -1;
}

How do I read this function declaration?
This is an non-prototype declaration. Prior to the standardization of C,
this was the only way to declare functions. It is still a permitted way
to do so, though it should be avoided. The above declaration declares
the same interface for time() as the prototype

time_t time(time_t *timer)
{
...

The key difference is that the prototyped declaration causes argument
type checking and automatic argument conversions. With the prototype,
you'll get a diagnostic message if you pass an argument that can't be
implicitly converted to 'time_t *', and if you pass an argument that
isn't time_t*, but is implicitly convertible to time_t* (such as a void*
argument), it will be implicitly converted.

With the non-prototyped declaration, there will be no diagnostic, and no
automatic conversion. In general, passing any argument to time() that
isn't a time_t* will be silently dangerous.
Oct 15 '08 #3
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"
Oct 15 '08 #4
On Wed, 15 Oct 2008 14:22:24 +0000, Richard Heathfield wrote:
Nickolai Leschov said:
>Hello,

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


That's very old C - it's called "K&R style", and nobody uses it any
more.
With the exception of the Minix guys, perhaps :)
Nowadays, we'd write this as:

time_t time(time_t *timer)
{

This newer form (which is now a couple of decades old!) is known as a
"prototype", and is intended to give the compiler greater scope for
type-checking.
Oct 15 '08 #5
On 15 Oct, 15:22, Richard Heathfield <r...@see.sig.invalidwrote:
Nickolai Leschov said:
/* Return the time now, and store it in *TIMER if not NULL. **/
time_t
time (timer)
* * * time_t *timer;
{

That's very old C - it's called "K&R style", and nobody uses it any more.
if only...

--
Nick Keighley
Oct 16 '08 #6

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

Similar topics

2
by: Holger Marzen | last post by:
Hi all, I want to upgrade Postgres 7.1.3 on an old Debian Slink machine (with glibc 2.0.7 and Kernel 2.2.17). That machine runs fine and I can not simply upgrade the OS because it's a busy 24/7...
1
by: Slavisa | last post by:
When I make my program on RedHat 9.0 everything goes fine, but when I try to make on Red Hat 7.2 I get following errors: logic2_msgcln.c:178: warning: initialization makes integer from pointer...
14
by: Stegano | last post by:
I am learning C Programming after working with Java for 5 years. I want to know where can I find the source files for C language itself. For example strcat is a function, which concatenates two...
0
by: JM | last post by:
Hi, I want to upgrade glibc on one of my box.. and i have installed postgres via source.. just incase I updated the glibc do I have to recompile postgres? TIA, jm ...
4
by: Stian Karlsen | last post by:
Hi. I'm getting an error in my program. It doesn't occur each time even if the same things happend in my program each time I run it. There will however be different values used for calculations in...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
6
by: zorba | last post by:
Hi , I would like to see the source of C library. gcc has glibc.so which contains all the code of the C library Implementation. How can i view the source code in web. -Zorba
2
by: akhilesh.noida | last post by:
I am trying to compile glibc-2.5 for ARM based board. But I am getting errors while configuring it. Please check and give your inputs for resolving this. configure command : $...
1
by: mars | last post by:
Which file is the "printf" implemention in glibc? The stdio.c is very small. It seems using __printf_chk (__USE_FORTIFY_LEVEL - 1, __VA_ARGS__) And __printf_chk using __nldbl___vfprintf_chk, but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.