Gcc global variables

I was recently asked about global registration variables in an interview. I mixed up, saying that any global variable will be stored in the data segment. But then I was asked about the GCC. After the interview, I came to the conclusion that gcc supports global register variables.

#include<stdio.h>

register int var asm("ebx");  //storing global variable in register explicitly

int main(void)
{
.......
}

Here is the link https://gcc.gnu.org/onlinedocs/gcc/Global-Reg-Vars.html#Global-Reg-Vars

But now I am confused in my lifetime and scope and will it work as a normal global variable or as a register variable? Also, is there any method or some command in gcc so that we are sure that the compiler will not just ignore the keyword registerand will be stored in a real register?

+4
source share
1 answer

As many people have noted, registry backups around the world are generally poor. I believe the original intention here was (from docs ):

, , , .

, , , . ( ) .

, , .

. , :

, , , . - .

, , COMPILED , . , LINK , , .

qsort. , qsort c runtime ( ), qsort ( ), , qsort .

, - ? :

, , .

:

, ( ).

:

register

, . (- ) asm("ebx"), . , , var ebx.

+4

All Articles