The & (address) operator and register allocation

Anton Rang rang at cpsin3.cps.msu.edu
Sat Dec 3 03:43:38 AEST 1988


I was thinking about RISC machines, and other machines with a lot of
registers, and came up with a question.  Since the C language doesn't
have call-by-reference, is it possible to allocate variables which are
passed by reference into registers?
  For example, the C code:

	scanf("%d", &N);

  would require that the address of N be taken to read it from the
standard input.  If I then have a loop:

	for (i=0; i<N; i++) { ... }

would the final program have to read N from memory each time?  Or does
the C standard provide that some keyword (like 'volatile') be used to
avoid possibly unsafe optimizations (like moving N into a register in
the above example--the address of N could have been saved in scanf() ).
  Are there any architectures which allow taking the "address" of a
register (say, having a reserved page)?

+---------------------------+------------------------+----------------------+
| Anton Rang (grad student) | "VMS Forever!"         | "Do worry...be SAD!" |
| Michigan State University | rang at cpswh.cps.msu.edu |                      |
+---------------------------+------------------------+----------------------+



More information about the Comp.lang.c mailing list