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

ctime \n rationale

Hi to all,
I'm just curious about the rationale of having ctime() put a new line
character at the end of its return value, as:

"Thu Nov 24 18:22:48 1986\n\0"

Personally, I find it stupid and resource wasting.

Does anyone have a good explanation about why it's done this way?

Tnx, regards.

--
Pietro Cerutti

PGP Public Key:
http://gahr.ch/pgp
Jun 24 '07 #1
8 3206
In article <5a***************************@news.hispeed.ch>,
Pietro Cerutti <ga**@gahr.chwrote:
>I'm just curious about the rationale of having ctime() put a new line
character at the end of its return value, as:

"Thu Nov 24 18:22:48 1986\n\0"

Personally, I find it stupid and resource wasting.

Does anyone have a good explanation about why it's done this way?
Probably because its original purpose was to implement the date
program in unix.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Jun 24 '07 #2
Richard Tobin wrote:
In article <5a***************************@news.hispeed.ch>,
Pietro Cerutti <ga**@gahr.chwrote:
>I'm just curious about the rationale of having ctime() put a new line
character at the end of its return value, as:

"Thu Nov 24 18:22:48 1986\n\0"

Personally, I find it stupid and resource wasting.

Does anyone have a good explanation about why it's done this way?

Probably because its original purpose was to implement the date
program in unix.
Even in that case, I would had written:
printf("%s\n", ctime(time(NULL)));
instead. Don't you agree?
>
-- Richard

--
Pietro Cerutti

PGP Public Key:
http://gahr.ch/pgp
Jun 24 '07 #3
On Sun, 24 Jun 2007 16:58:21 +0200, in comp.lang.c , Pietro Cerutti
<ga**@gahr.chwrote:
>Richard Tobin wrote:
>Probably because its original purpose was to implement the date
program in unix.

Even in that case, I would had written:
printf("%s\n", ctime(time(NULL)));
instead. Don't you agree?
But then the function would not be /implementing/ the unix 'date'
programme.

But surely this is no big deal - if you don't want it, rip it off.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jun 24 '07 #4
In article <8c***************************@news.hispeed.ch>,
Pietro Cerutti <ga**@gahr.chwrote:
>>I'm just curious about the rationale of having ctime() put a new line
character at the end of its return value, as:
>Probably because its original purpose was to implement the date
program in unix.
>Even in that case, I would had written:
printf("%s\n", ctime(time(NULL)));
instead. Don't you agree?
Oh yes. I'm just guessing an explanation, not trying to justify it.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Jun 24 '07 #5
Pietro Cerutti wrote:
Hi to all,
I'm just curious about the rationale of having ctime() put a new line
character at the end of its return value, as:

"Thu Nov 24 18:22:48 1986\n\0"

Personally, I find it stupid and resource wasting.

Does anyone have a good explanation about why it's done this way?
Well, it is defined in terms of an English-language representation of
the time. That is, it is equivalent (for the purposes of this
discussion) to "asctime(localtime(tod))".

As suggested else-thread, this is probably just legacy from Unix system
usage.
--
clvrmnky <mailto:sp******@clevermonkey.org>

Direct replies will be blacklisted. Replace "spamtrap" with my name to
contact me directly.
Jun 25 '07 #6
In article <5T*****************@nnrp.ca.mci.com!nnrp1.uunet.c a>,
Clever Monkey <sp******@clevermonkey.org.INVALIDwrote:
>As suggested else-thread, this is probably just legacy from Unix system
usage.
In Third Edition Unix, it didn't have a linefeed. Nor did it include
the day of the week or the year. The BUGS section of the manual page
says:

The routine must be reassembled for leap year.
Dec 31 is followed by Dec 32 and so on.

I'm not sure how this was supposed to work, since the manual page is
dated 1973, and time() returned seconds since Jan 1 1972. time()'s
BUGS section says:

The time is stored in 32 bits. This guarantees a
crisis every 2.26 years.

Maybe they really reset the clock every new year.

By Sixth Edition, ctime() was as we know it now.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Jun 25 '07 #7
Richard Tobin wrote:
In article <5T*****************@nnrp.ca.mci.com!nnrp1.uunet.c a>,
Clever Monkey <sp******@clevermonkey.org.INVALIDwrote:
>As suggested else-thread, this is probably just legacy from Unix system
usage.

In Third Edition Unix, it didn't have a linefeed. Nor did it include
the day of the week or the year. The BUGS section of the manual page
says:

The routine must be reassembled for leap year.
Dec 31 is followed by Dec 32 and so on.

I'm not sure how this was supposed to work, since the manual page is
dated 1973, and time() returned seconds since Jan 1 1972. time()'s
BUGS section says:

The time is stored in 32 bits. This guarantees a
crisis every 2.26 years.
I wonder what that means? Seems to me that we have 4,294,967,295
seconds since Jan 1, 1970 to play with (according to POSIX, anyway) and
the C runtime just accepts what it gets from the hosted environment in
terms of seconds since epoch.

Of course, UTC did not exist in its present form until 1972, so values
below 63072000 are not precisely defined.

Still have no idea why the line-feed is added on text representations of
time constructed by ctime() and friends, but my guess is that it was a
convenience for the most common (in English) representation of the
current time.

That is, one should be able to construct any locale-specific string with
or without any trailing whitespace you like using strftime(), while
asctime() and ctime() were kept as reasonable defaults for typical usage.

Just guessing, though.
--
clvrmnky <mailto:sp******@clevermonkey.org>

Direct replies will be blacklisted. Replace "spamtrap" with my name to
contact me directly.
Jun 25 '07 #8
In article <LJ******************@nnrp.ca.mci.com!nnrp1.uunet. ca>,
Clever Monkey <sp******@clevermonkey.org.INVALIDwrote:
> The time is stored in 32 bits. This guarantees a
crisis every 2.26 years.
>I wonder what that means?
Presumably time was stored in 1/HZ s (where HZ=60) internally.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Jun 25 '07 #9

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

Similar topics

3
by: Kevin | last post by:
Hello: I am trying to find documentation on using the ctime library as I need to be able to instantiate an object to keep track of the time when a certain event occurs. I also need to be able...
1
by: wukexin | last post by:
I write my own class Cfile, I want to know what about implement ctime().Who help me? My use function ctime, I sign it with $$$. my class Cfile: #------------------------ file.h...
5
by: berkay | last post by:
long num,num1; char *first; char *last; num=ilk.getTime();//gets time first=ctime(&num); cout.flush(); fflush(stdin); 1) cout<<"first:"<<first;
2
by: Hao Xu | last post by:
Hi everyone! I think that everyone knows ctime() in glibc: The ctime(), gmtime() and localtime() functions all take an argument of data type time_t which represents calendar time. When ...
2
by: Chris | last post by:
Hello, How can i convert a C++ CTime (4 bytes) into a C# DateTime ? (my CTime is read in a file). Thanks, -- Chris
4
by: Gary Wessle | last post by:
Hi I am not getting current time with this program, what am I doing wrong? #include <ctime> #include <iostream> using namespace std; #define P(x) cout << #x " = " << (x) << "\n";
11
by: aisling.cronin | last post by:
Hi I am using ctime to convert the following string 1144412677847 .... Please could some one to double check if they get the same result as me (The Time is Sun Nov 02 09:11:51 2031). It seems...
4
by: Pietro Cerutti | last post by:
Hi group, #include <stdio.h> #include <unistd.h> #include <time.h> int main(void) { time_t t1, t2; char *st1, *st2;
1
by: parag_paul | last post by:
I am try ing to use ctime with the type time_t , I used .... time_t t = time(0); char* sc = ctime( &t); printf ("%s\n", sc); ....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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...
0
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...
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
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,...
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.