473,748 Members | 4,065 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2928
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_Keit h) 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.i nvalidwrote:
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
2372
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 machine. When I try to compile PostgreSQL 7.2.4 or 7.4.1 then I get |gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations |-I../../../src/include -D_GNU_SOURCE -c hba.c -o hba.o
1
2039
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 without a cast logic2_msgcln.c:178: initializer element is not constant logic2_msgcln.c:178: warning: data definition has no type or storage class logic2_msgcln.c:185: parse error before `void' logic2_msgcln.c:225: parse error before `('
14
2331
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 strings. I want to read how this function is implemented in its native form, where can I find its corresponding .c file. I am using gcc version 3.3.1 (Thread model POSIX) on cygwin with Eclipse IDE. A grep on a function name lists many .h and .c...
0
1135
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 ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
4
10852
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 the program. The error happends suddenly and at different times. I load quiet alot of data into my program. I'm wondering if there are anyone witch are familiar with this sort of error, and has some good ideas for what may be wrong. What is...
232
13317
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 set of examples, after decoding the HTML FORM contents, merely verifies the text within a field to make sure it is a valid representation of an integer, without any junk thrown in, i.e. it must satisfy the regular expression: ^ *?+ *$ If the...
6
1441
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
6360
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 : $ ../glibc-2.5/configure --prefix=/mnt/new/Mars/glibc_HQ_test/GLIBC/ install/ --with-__thread --enable-kernel=2.6.11 --enable-shared
1
4621
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 __nldbl___vfprintf_chk using __printf_chk. I found the implement as following, I can not understand how it works. int attribute_hidden __printf_chk (int flag, const char *fmt, ...) { va_list arg; int done;
0
8826
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9534
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9316
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9241
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8239
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2211
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.