View unanswered posts | View active topics It is currently Tue Nov 25, 2014 6:06 pm






Reply to topic  [ 3 posts ] 
element access for arrays not working with paranthesis 
Author Message
Rookie

Joined: Sat Dec 04, 2010 10:32 am
Posts: 13
Post element access for arrays not working with paranthesis
Hi,

in RobotC 3.6, this code compiles:

Code:
task main()
{
   string test[] = {"entry1", "entry2", "entry3", "another one", "final one"};
   nxtDisplayCenteredTextLine(0, "< %s >", test[2]);
}


while this doesn't:

Code:
task main()
{
   string test[] = {"entry1", "entry2", "entry3", "another one", "final one"};
   nxtDisplayCenteredTextLine(0, "< %s >", (test)[2]);
}


Is that a bug? How can I dereference a pointer to an array and look up an element of the array? (*testPointer)[2] won't work.

--Felix


Sun May 12, 2013 1:35 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3289
Location: Rotterdam, The Netherlands
Post Re: element access for arrays not working with paranthesis
What exactly are you trying to achieve? The following code does exactly what it is supposed to do:
Code:
task main()
{
   string test[] = {"entry1", "entry2", "entry3", "another one", "final one"};
   for (int i = 0; i < 5; i++)
   {
     writeDebugStreamLine("< %s >", test[i]);
   }
}

What are you looking to dereference and why? This also works quite nicely:
Code:
task main ()
{
   string test[] = {"entry1", "entry2", "entry3", "another one", "final one"};
   string *foo = &test;
   
   for (int i = 0; i < 5; i++)
   {
     writeDebugStreamLine("< %s >", *(foo + i));
   }
 }

_________________
| 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]


Sun May 12, 2013 4:17 pm
Profile WWW
Rookie

Joined: Sat Dec 04, 2010 10:32 am
Posts: 13
Post Re: element access for arrays not working with paranthesis
Hi,

that seems to work for me, thanks!

I was trying to do something like that:

Code:
nxtDisplayCenteredTextLine(3, "< %s >", *((menu->labels) + (*selection)));


--Felix


Mon May 13, 2013 5:25 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 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.