NO

Author Topic: Function Parameters: pass-by-reference  (Read 2797 times)

chassan

  • Guest
Function Parameters: pass-by-reference
« on: April 16, 2010, 09:26:40 PM »
Hello folks,

With Pelles C, the following function declaration gets a compiler error:
int swap(int &intA, int &intB);

However, an application with the same function in MS Visual Studio compiles and runs as expected.

I realize this can (and probably should) be done using pointers, but doesn't ANSI C allow function parameters to be declared as by-reference using something like this?  int &intA

Thanks for any help!
Chris


Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: Function Parameters: pass-by-reference
« Reply #1 on: April 16, 2010, 11:40:47 PM »
The declaration is int swap(int *intA, int *intB);, but you call it value = swap(&intA, &intB);.
---
Stefan

Proud member of the UltraDefrag Development Team

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Function Parameters: pass-by-reference
« Reply #2 on: April 17, 2010, 06:45:44 PM »
int swap(int &intA, int &intB);

This is a declaration for C++, perhaps Visual Studio can compile it C-mode. Pelles C has a pure C compiler, so it does not understand it.
best regards
 Alex ;)