Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 28, 2024, 09:48:18 21:48


Login with username, password and session length


Pages: [1]
Print
Author Topic: Does Hi-tech support pass by reference?  (Read 4537 times)
0 Members and 1 Guest are viewing this topic.
piedos
Newbie
*
Offline Offline

Posts: 9

Thank You
-Given: 0
-Receive: 0


« on: December 07, 2006, 07:59:25 19:59 »

Code:
#include <pic18.h>
#include <conio.h>
#include <stdio.h>

void f1(int * x);
void f2(int & x);



void f1(int * x){

*x *= *x;
}

void f2(int & x){

x *= x;
}

int main(){

int a=22;
f1(&a);
f2(a);
puts("Hi");
while(1);

return 0;
}

No problem when passing a value by pointer, but gives error whilst triying with reference.


Executing: "C:\Program Files\HI-TECH Software\PICC-18\9.50\bin\picc18.exe" -C -E"main.cce" "main.c" -O"main.obj" -Zg9 -O -ASMLIST -Q -MPLAB -18F452
Advisory[1207]   : some of the command line options you are using are now obsolete
Advisory[1208]   : use --help option or refer to the user manual for option details
Error[194] D:\Proje\hi-tech\roga2\main.c 7 : ")" expected
Error[194] D:\Proje\hi-tech\roga2\main.c 16 : ")" expected
Error[285] D:\Proje\hi-tech\roga2\main.c 19 : no identifier in declaration
Warning[374] D:\Proje\hi-tech\roga2\main.c 19 : missing basic type; int assumed
Error[314] D:\Proje\hi-tech\roga2\main.c 19 : ";" expected
Halting build on first failure as requested.
BUILD FAILED: Thu Dec 07 21:56:01 2006


All errors are about f2 function
Logged
aProgrammer
Junior Member
**
Offline Offline

Posts: 62

Thank You
-Given: 70
-Receive: 258


« Reply #1 on: December 08, 2006, 10:32:06 10:32 »

references are a C++ feature.

Hi-tech is a C compiler not a C++

but references are just hiden pointers...
Logged
piedos
Newbie
*
Offline Offline

Posts: 9

Thank You
-Given: 0
-Receive: 0


« Reply #2 on: December 08, 2006, 05:10:17 17:10 »

references are a C++ feature.

Hi-tech is a C compiler not a C++

but references are just hiden pointers...

if they are c++ specific, why CCS C accepts?

if they are hidden pointers why I can't use
ref++;
for a reference?

if they are hidden pointers, why reference function
 generates less ASM code than a pointer function?
Logged
swapgo
Newbie
*
Offline Offline

Posts: 8

Thank You
-Given: 0
-Receive: 0


« Reply #3 on: December 19, 2006, 11:37:34 11:37 »



     C++ alone has this feature. C cannot do the pass by reference. It can do call by reference only.

Try with any of the ANSI C compilers.

 Hi-Tech C is strictly ANSI. But ccsc is not.

 I can say CCSC is user friendly PIC Microcontroller Cross Compiler. I cannot say it is a standard one.
 
 So don't try to conmpare CCSC with any of the standard C Compilers.

 Tryout even with GCC also.

Regards
Gopi
Logged
robban
Senior Member
****
Offline Offline

Posts: 265

Thank You
-Given: 34
-Receive: 38


Warrior


WWW
« Reply #4 on: December 19, 2006, 12:25:28 12:25 »

Well, that settles it...
Logged

Code Warrior
hate
Hero Member
*****
Offline Offline

Posts: 555

Thank You
-Given: 156
-Receive: 355


« Reply #5 on: December 19, 2006, 10:39:24 22:39 »

Some features of C++ are supported by some c compilers. For example "//" is also a c++ feature but most c compilers support it! So you have to check the compiler manual for a specific feature you need.

Regards...
Logged

Regards...
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC