The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Does KSH support data type conversion? joshuaduan Shell Programming and Scripting 2 06-26-2007 04:12 AM
Value too large to be stored in data type??? limame AIX 5 06-18-2007 11:35 PM
data type limitation ALTRUNVRSOFLN High Level Programming 2 11-01-2005 06:30 PM
FILE data type milhan High Level Programming 6 01-28-2005 08:49 PM
gzip:Value too large for defined data type dangral UNIX for Dummies Questions & Answers 1 10-14-2003 05:11 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-14-2005
whatisthis's Avatar
whatisthis whatisthis is offline
Registered User
  
 

Join Date: Aug 2004
Posts: 175
time_t data type-- what does start +1 mean?

Hi,
I am trying to understand an very old C program.

....
time_t start, end;
ptr = localtime(&start);
...
fprintf(out, "%-35s 01 %5s %2s %10d 1 5 /tty/M%d/%02d %24s", buffer3, job, ver, start, mach_num,atoi(buffer), asctime(ptr));

fprintf(out, "%-35s 03 %5s %2s %10d 1 5 /tty/M%d/%02d %24s", buffer3, job, ver, (start + 1), mach_num,atoi(buffer), asctime(ptr));
.....

what does (start+1) do here?
What about asctime(ptr)?



Thanks a lot!!

.
  #2 (permalink)  
Old 09-15-2005
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,802
May I make a suggestion? asctime() is part of the standard C library, so the man page

Code:
man asctime

will tell you everything you need to know.

start+1 just displays one more than the unsigned long value of start.
  #3 (permalink)  
Old 09-15-2005
whatisthis's Avatar
whatisthis whatisthis is offline
Registered User
  
 

Join Date: Aug 2004
Posts: 175
Hi
I kind of understood the meaning for those two questions but just wanted to verify it.

Here is the my real problem:
When the below code running, sometimes the result of end-2 is greater than end -1, sometime it isn't.

Does anyone know what could be the reason?

Thanks a lot!


.....
time_t start, end;
.....
fprintf(out, "%-35s 55 %5s %2s %10d 1 5 /tty/M%d/%02d %24s", buffer3, job, ver, end - 2, mach_num,atoi(buffer), asctime(ptr));

fprintf(out, "%-35s 50 %5s %2s %10d 1 5 /tty/M%d/%02d %24s", buffer3, job, ver, (end - 1), mach_num,atoi(buffer), asctime(ptr));
  #4 (permalink)  
Old 09-15-2005
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,802
What you've posted so far doesn't give enough information. Are there any intervening lines between the two fprint() statements?

This looks like an attempt to check time sync on two different boxes.
  #5 (permalink)  
Old 09-15-2005
whatisthis's Avatar
whatisthis whatisthis is offline
Registered User
  
 

Join Date: Aug 2004
Posts: 175
seconds after 1970

No, there is no intervening lines between the two fprint() statements.
But this is this : ptr = localtime(&end);

I know that this part of the code suppose to write to a log file format like below. But sometimes the number with blue color in the second line is lesser than the number with blue in the first line. The number should be the seconds after 1970. It happened randomlly.

6174 Name 55 20261 02 1110798898 1 5 /tty/M1/08 Mon Ma
r 14 06:15:00 2005
6174 Name 50 20261 02 1110798002 1 5 /tty/M1/08 Mon Ma
r 14 06:15:00 2005
===============================================





5514 Name 55 00000 03 1126647298 1 5 /tty/M1/03 Tue Sep 13 17:35:00 2005
5514 Name 50 00000 03 1126647299 1 5 /tty/M1/03 Tue Sep 13 17:35:00 2005

Last edited by whatisthis; 09-15-2005 at 11:04 AM.. Reason: addition
  #6 (permalink)  
Old 09-15-2005
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,802
Under some heavy-duty circumstances and with some versions of unix:
the order that data is written to a file may not be preserved. We had an old DEC-unix box that did that. I don't know that this is what you are seeing, but it's possible.

You can correct the problem with fflush():
Code:
fprintf(..........);
fflush(out);
fprintf(...........);

This has nothing to do with C in particular.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0