A different view of volatile

Bjorn Engsig be at dde.uucp
Fri May 6 18:37:27 AEST 1988


In article <13120 at brl-adm.ARPA>, christiansen at chewi.che.wisc.EDU (REED CHRISTIANSEN) writes:
...
> VOLATILE (that is, whose value(s) can change asynchronously due to
> action by another process or by hardware action) ...
            ---------------       ---------------

That's not the only cases, consider:

----------------- get_value.c ------------------
static int *pointer;

set_address(ptr); int *ptr;
  { pointer = ptr };

get_value()
  { /* stuff */ 
    if (value_found)
      { *pointer = value; return 1;  }
    else
      return 0;
  }

------------------ main.c -------------------
main()
  {
  /* volatile */ int result;
  set_address(&result);
  while (get_value())  process_it();
  }

Such kind of code is for example found in database host language
interfaces, where you first define where to store the data from
the database, and later you fetch the data until no more data are
found.  In real life, the set_address() is called a various number
of times (probably many times) and then get_value() knows the addresses
and doesn't need a large and varying number of parameters.

This is not to oject against volatile, I know where I should put it.

-- 
Bjorn Engsig @ Dansk Data Elektronik A/S, Herlev, Denmark

Email: be at dde.dk			Phone:	+ 45 2 84 50 11
Email: ..!uunet!mcvax!dkuug!dde!be	Fax:	+ 45 2 84 52 20



More information about the Comp.lang.c mailing list