Pelles C forum

C language => Beginner questions => Topic started by: chassan on April 16, 2010, 09:26:40 PM

Title: Function Parameters: pass-by-reference
Post by: chassan 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

Title: Re: Function Parameters: pass-by-reference
Post by: Stefan Pendl 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);.
Title: Re: Function Parameters: pass-by-reference
Post by: AlexN on April 17, 2010, 06:45:44 PM
Quote from: chassan on April 16, 2010, 09:26:40 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.