Re: C program hangs in ctime on Linux/Alpha

David Mosberger-Tang (davidm@azstarnet.com)
Fri, 13 Sep 1996 18:10:38 -0700


>>>>> On Thu, 12 Sep 1996 09:08:21 -0700, olsson@cs.ucdavis.edu said:

Olsson> The attached C program hangs on Alphas running 2.0.17 and
Olsson> 2.0.18. (To be clear, I mean the program just sits there
Olsson> apparently looping, although the system remains functional
Olsson> to other processes.) gdb shows it in:

Olsson> The program does not hang on x86 running Linux or on an
Olsson> Alpha running OSF/1.

That doesn't mean the program is correct. The version below works
fine. With gcc -Wall, you'd have noticed immediately (assuming you
don't mind including <time.h>). The program is wrong because it
assumes time_t==int. On Linux/Alpha, time_t is a long.

--david

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

static void P_ctime(); static void P_time();

int main() { time_t t1, t2; int i1; time_t *p1, *p2;

char *result; char *ctime();

printf("begin external test\n");

/**** w/o time *or* ctime call, it doesn't hang. ****/

t1=1; t2=2;

p1 = &t2;

i1=time(p1);

t1= i1;

printf("before ctime\n");

/* with p2 = &i1; instead of following, it doesn't hang. */

p2 = &t1;

result = "abcdefghijklmnopqrstuvwxyz";

/*original*/ result=ctime(p2);

printf("after ctime\n");

exit(1); }