View unanswered posts | View active topics It is currently Fri Oct 31, 2014 12:17 am






Reply to topic  [ 5 posts ] 
Why is this syntax not supported? 
Author Message
Rookie
User avatar

Joined: Thu Oct 16, 2008 10:07 am
Posts: 6
Location: Between Here and There
Post Why is this syntax not supported?
Most people when accessing a struct member from a pointer to a struct seem to use this syntax:
Code:
pointer->var

However, the just as 'C valid' syntax
Code:
(*pointer).var

does not seem to work in RobotC.
The latter is my preferred syntax (I think it is more descriptive of what you are actually doing), and I was wondering why RobotC does not support it.
More details about this syntax here: http://www.itee.uq.edu.au/~comp2303/Leslie_C_ref/C/SYNTAX/struct.html#arrow
Since this does not compile properly in RobotC, I have to wonder if the pointer system is properly implemented. If it was, then the dereferencing (*pointer) should allow the rest of the statement to treat it as local value, not an address to the pointer.

Edit: Now that I think about it, this probably should be in the RobotC 1.x board, but whatever.

_________________
Code:
(*prev).next = (*toDelete).next;
delete toDelete;

//if only forgetting were
//this easy for me

assert "It's going to be okay";

//-xkcd


Thu Oct 16, 2008 10:24 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post Re: Why is this syntax not supported?
Sorry mate, no support for pointers in RobotC. To access a struct's member variable, use the dot notation, eg, struct.member

Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Thu Oct 16, 2008 10:36 am
Profile WWW
Rookie
User avatar

Joined: Thu Oct 16, 2008 10:07 am
Posts: 6
Location: Between Here and There
Post Re: Why is this syntax not supported?
That's odd.

Then how do they get by calling it RobotC, without standard support for pointers. Pointers are a rather integral part of the language, saving tons of time and memory like by passing variables to functions by reference instead of by value. For anything except basic linear programming staying mainly in the main() function, pointers are a god-send.

It is a shame that FTC won't let us use other NXT languages like NXC/NBC (that natively runs on my computer, unlike RobotC). If it is not even really C, I don't see the point except maybe to introduce some people to C like syntax, but even then, if they are only allowed to pass vars by value to functions, that will encourage bad practice when they move on to real C programming.

Now I have not had time to read through all of the documentation for the compiler, but do they at least have some way to use malloc() and friends, without pointers I would assume.

_________________
Code:
(*prev).next = (*toDelete).next;
delete toDelete;

//if only forgetting were
//this easy for me

assert "It's going to be okay";

//-xkcd


Thu Oct 16, 2008 10:51 am
Profile
Professor

Joined: Fri Sep 19, 2008 1:22 am
Posts: 200
Post Re: Why is this syntax not supported?
RobotC does in fact support pointers and pass by reference. RobotC's pointer support isn't ANSI standard but it is generally sufficient for the kinds of situations you enumerated. In fact, if you try passing a struct to a function by value you will get a compiler warning that it doesn't support passing structs by value. It doesn't prevent the compiliation, it just warns you and passes the struct by reference.

However, we do agree on a couple of critical points:

1) RobotC needs better documentation about the differences between it and ANSI C.
2) It would be nice to improve RobotC's pointer support.

The good news is that both of these issues are already on their task list. For example, if you look at Help / What's New and scroll down to the notes for the 1.17 release you will find the following change description:

- Partial (and preliminary) support for 'pointer' variables and the "->" operator.

You might wonder why they haven't finished the pointer support since then. The answer is that they have had to focus on adding support for the new hardware used for the various FIRST competitions in time for this year's tournaments.

Perhaps Dick can give us a clue as to when we might see additional pointer support.

_________________
Jeff McBride
Benson Robotics Club


Thu Oct 16, 2008 11:24 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: Why is this syntax not supported?
I'm with you, I complained the lack of pointer management already since many months.
no new()
no malloc()
no free()
no *
no ->

Unfortunately, RobotC is not real C and not ANSI C!

the only thing they've got is a function call by reference (C++):
void myFunc(int &refvar);

They say the lack of pointers is because of the basic Lego firmware which doesn't enables any heap.

But to my opinion: who needs the Lego firmware? Why not write an own one?

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Thu Oct 16, 2008 11:25 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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 post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.