CPU with address GPR files, address of register variables and smoothing between memory and registers

Background

Some processors, such as Atmel AVR , have a general-purpose register file, which is also addressed as part of the main memory - see Figure 7-2 in section 7.4 and the paragraph after the number.

What did the WG14 think?

Given this, why committee C decided to do

register int ri;
int* pi = &ri;

ubiquitously poorly formed, in accordance with note 101 to N1124 section 6.7.1? Wouldn't undefined or implementation-defined behavior make more sense, given that the code above makes sense on at least one processor, and C bends backward to accommodate much more alien (and weaker!) Goals than AVR?

101) An implementation can process any declaration registersimply as a autodeclaration. However, regardless of whether address storage is actually used, the address of any part of an object declared using the storage class specifier registercannot be calculated either explicitly (using the unary operator &, as discussed in 6.5.3.2) or implicitly (by converting the array name to the pointer, as described in 6.3.2.1). Thus, the only statement that can be applied to an array declared using the storage class specifier register sizeof.

I just changed the CPU register through a pointer. Wat ?!

, GCC, , . , :

register int ri asm("r15") = 0;
int* pi = (int*)0x15;
/* pi now aliases ri */
*pi = 42;
/* ri is 42 now */
assert(ri == 42);

GCC ? , , - ... ?

+1
1

C - , , . C , ( , , , , ).

, register , . , ; , , . register C, , , register ( , ), , . , .

AVR , , , ( , , , auto ).

+4

Source: https://habr.com/ru/post/1683303/


All Articles