I would like to know how is it possible to pass registers as function arguments in C. Let's say I have something like this:

int main() {
    register a,b;
    a = b;
    register c = a;
    return 0;

I want to extract a = b as a new function. Considering what we do for variables, if I return register "a" as function return I will get this error: "function definition declared 'register'".
Another option is passing arguments as function variables But obviously it is not possible to pass a register az a pointer because they are not memory location to assign them an address. So, I am wondering what would be the correct way to extract "a = b" as a new function?

3 Years
Discussion Span
Last Post by Unimportant
int add( int * a, int * b )
  return *a + *b;
register int * a( & var1 ), * b( & var 2);
int c( add( a, b ) );

Considering you didn't define a type, I suggest you avoid using registers for the time being.

Edited by Unimportant


Thanks! Actually this is a type of code I need to extract, that's not my own code. I did not understand what you exactly did! Is there any simpler way to do that?


I created a regular function called add, which receives two pointers to integer as arguments, and returns an integer.

I declared two pointers to integer as registers, and instantiated them with the address of two arbitrary integers.

Finally, I instantiated an integer with the return value of the first function, accepting the two register variables as arguments.


For the purpose of understanding someone else's code, you can essentially ignore the register keyword altogether. The compiler itself probably does it better anyway.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.