Can a whole array be in some cpu register?

Since I am not very versed in processor registers, in general, and in any architecture, especially x86, and if the compiler is applicable using VC ++, I am curious that this is possible for all elements of an array with a small number of elements as an array of 1-byte characters with 4 elements that will be in some cpu register, since I know that this can be true for single primitives like double, integer, etc.

when we have a parameter as shown below:

void someFunc(char charArray[4]){
//whatever
}

Will this transfer of parameters be definitely performed by passing a pointer to a function, or will this array be in some cpu register, eliminating the need to pass a pointer to the main memory?

+3
source share
6 answers

Within one function, an array can be stored in one or several registers only if the compiler can create CPU instructions to manage it, as the code dictates. The standard does not really define what “something” means in the register. This is a private matter between the compiler and the debugger, and there may be a fine line between what is in the register and it is completely “optimized”.

, (. dribeas). , , , , . "" , , , , , , , , .

, , .

, , :

struct Foo {
    char a[4];
};

void FooFunc(Foo f) {
    // whatever
}

, . , , . , , .

+4

, . , , .. . ++ , :

void foo( char *a );
void foo( char a[] );
void foo( char a[4] );
void foo( char a[ 100000 ] );

. , , : , . , .

(google , MME ). , , , .

+5

5 , , (Borland/Turbo C/++ 1.0, Watcom C/++ v8.0, MSC 5.0, IBM Visual Age C/++, gcc DOS, Linux Windows) , .

, , , , ASM x86. , " ", .

+1

, , , . , , , , .

( x86 a[0] a[1], al ah eax, , , .)

+1

, V++ x86.

, . , , , - , , .

, , "", , ,

char x[4];
*((int*)x) = 36587467;

/FA ( : -))

"" , , , .

- ,

0

. register: register int i;

.

, 4 , ( ):

char c = *(charArray + 4);
-1
source

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


All Articles