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?

Recommended Answers

All 4 Replies

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.