Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
* Help in computing time....
@ 1995-06-21  4:00 Falguni Sarkar
  1995-06-21  4:00 ` Derick J.R. Qua-Gonzalez
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Falguni Sarkar @ 1995-06-21  4:00 UTC (permalink / raw)



I am using a DEC Alpha machine. When I try to compile the
following code I am facing problems. 

#include <stdio.h>
#include <time.h>

time_t tim1,*tp;
main(){
   tim1=time(tp);
   if(tp==NULL)
     printf("tp is NULL\n");
}

If I use cc then tp is always returned as NULL. If I use
gcc for compilation, no executable file gets created and
the following message is displayed.

In file included from /usr/include/sys/timers.h:99,
                 from /usr/local/lib/gcc-lib/alpha-dec-osf3.2/2.6.3/include/time.h:174,
                 from sample.c:2:
/usr/local/lib/gcc-lib/alpha-dec-osf3.2/2.6.3/include/sys/signal.h:225: field `sigev_value' has incomplete type


I need to evalute the physical time between two successive points
in one of my experimental program. Hence I am using the function
time(), which is returning me always NULL values or the programs
do not compile. I will highly appreciate any suggestion about
how to fix this.

Thanks in advance,

Falguni Sarkar.

E-mail : sarkar@ponder.csci.unt.edu
 
-- 
Falguni Sarkar          
Dept. of Computer Science
University of North Texas
Denton, TX 76203



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Help in computing time....
  1995-06-21  4:00 Help in computing time Falguni Sarkar
  1995-06-21  4:00 ` Derick J.R. Qua-Gonzalez
@ 1995-06-21  4:00 ` Michael W. Walker
  1995-06-27  4:00 ` D'Arcy J.M. Cain
  2 siblings, 0 replies; 4+ messages in thread
From: Michael W. Walker @ 1995-06-21  4:00 UTC (permalink / raw)


In article <3s884v$7qj@hermes.acs.unt.edu>,
Falguni Sarkar <sarkar@ponder.csci.unt.edu> wrote:
>
<snip>
>
>I need to evalute the physical time between two successive points
>in one of my experimental program. Hence I am using the function
>time(), which is returning me always NULL values or the programs
>do not compile. I will highly appreciate any suggestion about
>how to fix this.
>

I found clock_gettime() to be a solid solution for obtaining a real time clock.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Help in computing time....
  1995-06-21  4:00 Help in computing time Falguni Sarkar
@ 1995-06-21  4:00 ` Derick J.R. Qua-Gonzalez
  1995-06-21  4:00 ` Michael W. Walker
  1995-06-27  4:00 ` D'Arcy J.M. Cain
  2 siblings, 0 replies; 4+ messages in thread
From: Derick J.R. Qua-Gonzalez @ 1995-06-21  4:00 UTC (permalink / raw)


sarkar@ponder.csci.unt.edu (Falguni Sarkar) writes:
>I am using a DEC Alpha machine. When I try to compile the
>following code I am facing problems. 

>#include <stdio.h>
>#include <time.h>

>time_t tim1,*tp;
>main(){
>   tim1=time(tp);
>   if(tp==NULL)
>     printf("tp is NULL\n");
>}

>If I use cc then tp is always returned as NULL. 

Mr. Sarkar, the problem stems from the fact that time() cannot modify
the value of the pointer tp; it could only change the copy it has.
The argument of time, if non-NULL, is where a the time value is
stuffed, in addition to being returned, otherwise the argument is
ignored completely.  To get the time, either:

          time(&tim1);

or:

          tim1=time(NULL);

will work just fine and return the time to you in the variable tim1.


>Thanks in advance,
>Falguni Sarkar.


Best regards,


--
+----------------------------------------------------------------------------+
| Derick R. Qua-Gonzalez                                          | ________ |
| Department of High Energy Physics                               | \      / |
| California State University                                     |  \    /  |
| dqua@Prometheus.EarthLink.Net                                   |   \  /   |
|                                                                 | G  \/    |
+----------------------------------------------------------------------------+
|  It is better to be hated for what one is, than loved for what one is not. |
|                                  (A. Gide)                                 |
+----------------------------------------------------------------------------+




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Help in computing time....
  1995-06-21  4:00 Help in computing time Falguni Sarkar
  1995-06-21  4:00 ` Derick J.R. Qua-Gonzalez
  1995-06-21  4:00 ` Michael W. Walker
@ 1995-06-27  4:00 ` D'Arcy J.M. Cain
  2 siblings, 0 replies; 4+ messages in thread
From: D'Arcy J.M. Cain @ 1995-06-27  4:00 UTC (permalink / raw)


Falguni Sarkar (sarkar@ponder.csci.unt.edu) wrote:
>I am using a DEC Alpha machine. When I try to compile the
>following code I am facing problems. 

I think you would find it a problem on any platform.  If you want
to be a C programmer it is absolutely essential that you understand
pointers.  Read the FAQ carefully and study your textbook of choice.
If you don't understand pointers you aren't a C programmer.

>time_t tim1,*tp;

You have not initialized tp so, since it is declared outside of any
function, it is initialized as NULL (actually 0 which, in this context,
is a null pointer.)

>main(){
>   tim1=time(tp);

Given that tp is NULL, what does the man page say the effect is?
Look it up.

>   if(tp==NULL)

Since you never changed tp there isn't much point to testing it here.
There is no way for a function to modify a variable if all you send
it is the current value of the variable.  However, if tp were to be
initialized to the address of tim1 (and you don't assign the return
value to tim1 [*]) then time() *will* change the value of tim1 but it
still won't affect tp.

I think what you are trying to do is something like this:

...
tim1 = time(NULL); /* get current time */
... /* do stuff */
tim_diff = time(NULL) - tim1;

[*] actually it would just be redundent.

-- 
D'Arcy J.M. Cain (darcy@{planix|druid}.com)  |  Democracy is three wolves
Planix, Inc., Toronto, Canada                |  and a sheep voting on
+1 416 424 2871     (DoD#0082)    (eNTP)     |  what's for dinner.
      -- Info on Planix can be found at http://www.planix.com --



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1995-06-27  4:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1995-06-21  4:00 Help in computing time Falguni Sarkar
1995-06-21  4:00 ` Derick J.R. Qua-Gonzalez
1995-06-21  4:00 ` Michael W. Walker
1995-06-27  4:00 ` D'Arcy J.M. Cain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox