c++ passing arguments by reference and pointer

Viewed 19403

in c++

class bar
{
    int i;
    char b;
    float d;
};

void foo ( bar arg );
void foo ( bar &arg );
void foo ( bar *arg );

this is a sample class/struct and functions
i have some Qs

  • what's the difference between 1st and 2nd way of passing the argument in 'asm', size, speed ?
  • how the arguments are passed to the functions foo in each case ( in case of pointer i know the pointer is pushed on the stack )
  • when passing arguments, in terms of efficiency at ( speed, size, preferability ) which is better ?
  • what's the intel 'asm' syntax that corresponds each of the ways of passing arguments ?

i know what most say about "it doesn't matter on modern compilers and CPUs" but what if we're talking about Old CPUs or compilers?

thanks in advance

5 Answers

If you consider that it's good practice to validate pointer parameters before using them then, yes, pointers introduce extra overhead since references don't require such testing.

Related