(hopefully)simple question

Shaula Doyle shaula at maestro.mitre.org
Fri Apr 5 23:24:43 AEST 1991


related declrations from top;
struct timeval wait;
struct timeval * wait_ptr;
timeout is parameter, earlier write statement showed to be 10.

1  if (TRACE)printf("read and except masks set\n");
2  if (timeout < 0) wait_ptr = 0;  /* set timeout characteristics */
3  else {
4	  wait.tv_sec = timeout;   /* 0 is immediate return */
5	  *wait_ptr = wait;
6	}
7  if(TRACE)printf("timeout set to %d\n",timeout);

A bus error came between the two trace statements on the _second_
iteration of the loop in which this was enclosed.
I changed line 5 from
	*wait_ptr = wait;
to
	wait_ptr = &wait;

and that fixed it.  My question is: why?  what was wrong?  I know
that a segmentation error means I tried to write outside my program
address space, can someone give me an explanation of what a bus 
error is?  I hope this isn't considered a waste of time, this seemed
to me the kind of esoteric C question this group would like.
FYI: I'm using cc under SunOS 4.1.1

-thanks for the time- shaula

PS I regularly program in about 3 different languages, and I find
I get confused on basic syntax sometimes.  K&R seems to make a 
horrible reference for this sort of simple detail, and I was 
hoping someone could recommend a good alternative?  thanx again.
shaula at maestro.mitre.org



More information about the Comp.lang.c mailing list