CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Pointer and Reference Parameter Inquiry

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
chingB



Joined: 29 Dec 2003
Posts: 81

View user's profile Send private message

Pointer and Reference Parameter Inquiry
PostPosted: Sat Jun 11, 2005 8:48 pm     Reply with quote

Hi,

According to CCS reference manual...
Quote:

The compiler has limited support for reference parameters. This increases the readability of code and the efficiency of some inline procedures. The following two procedures are the same. The one with reference parameters will be implemented with greater efficiency when it is inline.


Code:

funct_a(int*x,int*y){
   /*Traditional*/
   if(*x!=5)
   *y=*x+3;
}

funct_a(&a,&b);

funct_b(int&x,int&y){
   /*Reference params*/
   if(x!=5)
   y=x+3;
}

funct_b(a,b);


In relation with this, the driver for DS1302 uses the reference parameter and it confuse me coz I usually use the * ptr symbol for passing data to a varaible.

Can anybody explain this such that I can be enlighten?
BTW, is this reference parameter method is an ANSI-C standard?

Would it be possible to change the function declaration:
Code:

From
void rtc_get_date(BYTE &day, BYTE &mth, BYTE &year, BYTE &dow);
void rtc_get_time(BYTE &hr, BYTE &min, BYTE *sec);

To
void rtc_get_date(BYTE *day, BYTE *mth, BYTE *year, BYTE *dow);
void rtc_get_time(BYTE *hr, BYTE *min, BYTE *sec);


then, I am going use the function such as:
Code:

void main() {
   byte day,mth,year,dow,hour,min,sec;

   rtc_init();

   while (TRUE) {
      rtc_get_date( &day, &mth, &year, &dow);
      rtc_get_time( &hour, &min, &sec );
            printf(lcd_putc,"%2X/%2X/%2X\n%2X:%2X:%2X",day,mth,year,hour,min,sec);
      delay_ms(250);
   }
}


I also simulate this code to Visual C++ and it says a syntax error!!! code listed below.
Code:

void ds1302_get_date(char &Day, char &Month, char &Year, char &DayOfWeek)
{
    Day = 0x05;      // get day
    Month = 0x10;    // get month
    Year = 0x05;     // get year
    DayOfWeek = 0x03; // get days of the week
    return;
}


void main()
{
   char Day;
   char Month;
   char Year;
   char DayOfWeek;

   ds1302_get_date(Day, Month, Year, DayOfWeek);
   getchar();
   return;
}


I guess VC++ does not support reference parameter? Am I right?

I need your insights on this matter.

Thank u.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jun 11, 2005 11:38 pm     Reply with quote

It does compile under MSVC++, but you have to give your file
an extension of .cpp, instead of .c

Here is a brief description of it on a C++ webpage:
http://www.cs.wisc.edu/~hasti/cs368/CppTutorial/NOTES/PARAMS.html#ref
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Sun Jun 12, 2005 8:37 am     Reply with quote

If the function is implemented inline and you used reference parms then I suspect the compiler wouldn't need to load temp variables for the parms. This also makes the function a little easier to read since some people have trouble with pointer notation.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group