[ create a new paste ] login | about

Link: http://codepad.org/QHkIOPAP    [ raw code | output | fork | 1 comment ]

joshua_cheek - C, pasted on Nov 26:
int i;

# 18 "pass_by_name_vs_pass_by_value.c"
int three_times( int a )
{
  int total = 0;
  total += a;
  ++i;
  total += a;
  ++i;
  total += a;
  return total;
}



int main( )
{

  int array[] = {1,2,3};

  i = 0;
  printf( "pass by name: %d\n" , ({ int total = 0; total += array[i]; ++i; total += array[i]; ++i; total += array[i]; total; }) );

  i = 0;
  printf( "pass by value: %d\n" , three_times(array[i]) );

  return 0;
}


Output:
1
2
pass by name: 6
pass by value: 3


Create a new paste based on this one


Comments:
posted by joshua_cheek on Nov 26
This is the output of http://codepad.org/WC3Ojunt after preprocessing it (gcc with the -E flag)

It shows how the macro gets embedded into the C code.
reply