prindle@NADC.ARPA (Frank Prindle) (10/05/88)
The "bug" in Power-C reported by Brian Hollander is not really a "bug". It was documented in the C-Power documentation (don't know about the Power-C documentation) that local scalar variables declared in a function without an explicit storage class are, by default, of storage class "register", where "register" means the compiler is free to use a quick volatile storage for the variables if it desires. Passing the address of a "register" variable is considered erroneous by any compiler, though Power-C can be faulted for not flagging the error. Virtually every other K&R implementation defaults the storage class for all local variables to "auto". Thus the declaration: int value; in most compilers is equivalent to: auto int value; but in Power-C is equivalent to: register int value; and naturally taking the address of value is not a valid thing to do for the reasons that Brian stated. There are two solutions to the "problem". First, any scalar variable which is to be the operand of an "&" operator can be explicitly declared "auto" (e.g. "auto int value;"). Second (and undocumented), is a special flag to the compiler (-a) which will force the K&R convention to be used (i.e. use "auto" when storage class unspecified); unfortunately, this is applied to *all* local variables compiled and can slow down the code quite a bit even though most of the variables aren't used with the address operator. Therefore, the "quick-fix" is using the -a option. The more careful fix is to explicitly declare the storage class of all variables. Sincerely, Frank Prindle Prindle@NADC.arpa