chingB
Joined: 29 Dec 2003 Posts: 81
|
Pointer and Reference Parameter Inquiry |
Posted: Sat Jun 11, 2005 8:48 pm |
|
|
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. |
|