PRB: Taking Address of Register Array Not Allowed per ANSI

ID Number: Q67036

6.00 6.00a 6.00ax | 6.00 6.00a

MS-DOS | OS/2

buglist6.00 buglist6.00a buglist6.00ax fixlist7.00

Summary:

SYMPTOMS

According to the ANSI specification, you may not explicitly or

implicitly compute the address of an object declared with register

storage-class. However, the Microsoft C and QuickC compilers DO

allow you to take the address of such an array declared with

register storage-class. The only operator that should be allowed to

be used with these types of arrays is sizeof.

STATUS

Microsoft has confirmed this to be a problem in C versions 6.0,

6.0a, and 6.0ax and QuickC versions 2.5 and 2.51 (buglist2.50 and

buglist2.51). This problem was corrected in C/C++ version 7.0.

More Information:

The sample code below should give an error according to ANSI, but no

errors or warnings are generated. In Section 3.5.1 of the ANSI

specification, there is a footnote (55) that includes the following

information:

...whether or not addressable storage is actually used, the address

of any part of an object declared with storage-class specifier

register may not be computed, either explicitly (by use of the

unary & operator) or implicitly (by converting an array name to a

pointer). Thus the only operator that can be applied to an array

with storage-class specifier register is sizeof.

Sample Code

-----------

void main(void)

{

register int array[10]; /* declared w/register storage-class */

int *ptr;

/* According to ANSI, none of the following should be allowed */

ptr = array; /* implicit address computation of array */

ptr = &array[0]; /* explicit address computation with '&' */

ptr = array + 5; /* computation based on address of array */

}

Additional reference words: 6.00 6.00a 6.00ax 7.00