View unanswered posts | View active topics It is currently Thu Jul 31, 2014 9:56 am






Reply to topic  [ 10 posts ] 
macro preprocessor and token "pasting" 
Author Message
Rookie

Joined: Wed Nov 17, 2010 2:52 am
Posts: 8
Post macro preprocessor and token "pasting"
Am I missing something or does the preprocessor not support the token pasting operator...

eg:

#define CREATE_REF(name) int mtx_##name ;

CREATE_REF(bob)

/====

fails
I haven't been able to find any examples in the forum that uses it... Just wondering I was trying to create a flexible Lock mechanism using macros to create the lock property, lock and unlock using the "x++ being atomic" assumtion.
But. I can't do very easily that if I can't create a macro that doesn't support the token pasting/concatenation operator..

--marcel


Wed Nov 17, 2010 3:10 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3165
Location: Rotterdam, The Netherlands
Post Re: macro preprocessor and token "pasting"
You might want to send this one to support@robotc.net, one of the developers will be able to answer that one, I'm sure.

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


Wed Nov 17, 2010 3:16 am
Profile WWW
Rookie

Joined: Wed Nov 17, 2010 2:52 am
Posts: 8
Post Re: macro preprocessor and token "pasting"
Thanks, I've sent off an email..

On a more general note.. is there a reference document somewhere that lists RobotC's "peculiarities"?
Some of them I already know, but it would be nice if they were all consolidated in one place.

I'm an old programmer but this is my first time with Robot C (I have a son on an FTC Team). He keeps asking embarrassing questions.. so I'm learning.

--marcel


Wed Nov 17, 2010 3:28 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3165
Location: Rotterdam, The Netherlands
Post Re: macro preprocessor and token "pasting"
No consolidated reference doc, no. What kind of peculiarities are you referring to? (there are more than one :))

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


Wed Nov 17, 2010 3:32 am
Profile WWW
Rookie

Joined: Wed Nov 17, 2010 2:52 am
Posts: 8
Post Re: macro preprocessor and token "pasting"
Well, I was hoping I wouldn't have to "discover" them on my own :-)...

I don't have any problem with learning all the Nxt programming parts of this, but just would like to know what the language implementation limitations are.

So things like:
- Pre-processor limitations (like the aforementioned issue.. no response yet from RobotC support) Are there any other non-standard limitations??
- Already know about the "global" local variables for functions.. Does this include arguments?
- are there any call stack depth limitations?
- array size limitations?
- Number of Task limitations?
- Already know that the functions are non-reEntrant..
- Already know there is no mutex support but it does appear that there may be hope there via buried, inactive code that looks like it might support semaphores at some point.
- Token naming restrictions
- Do Threads / tasks have priorities? ( I think not, but just checking)
- Can we write code that uses the ASM intrinsics? or do you have to be "special"?

Library limitations:
- File I/O or other stdc library pseudo-implementation limitations?

Just trying to see what pain I can expect :-)

--marcel


Wed Nov 17, 2010 5:14 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3165
Location: Rotterdam, The Netherlands
Post Re: macro preprocessor and token "pasting"
Quote:
- Already know about the "global" local variables for functions.. Does this include arguments?

I am not sure what you mean by this.

Quote:
- are there any call stack depth limitations?

No idea.

Quote:
- array size limitations?

You have about 16K variable space, so you need to stay within that. I think 2-dimensional is the maximum.

Quote:
- Number of Task limitations?

20 tasks

Quote:
- Do Threads / tasks have priorities? ( I think not, but just checking)

I think there is a way to do it, but I never have. Is there a reason you need this? My advice is to stay away from empty while loops, use EndTimeSlice() if you need something to wait for something in a while loop.

Quote:
- Can we write code that uses the ASM intrinsics? or do you have to be "special"?

You can't, not even special people can do it :)

I wouldn't go as far as using the word "pain". Perhaps "special features" would be more appropriate, hehe.

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


Fri Nov 19, 2010 3:04 am
Profile WWW
Rookie

Joined: Wed Nov 17, 2010 2:52 am
Posts: 8
Post Re: macro preprocessor and token "pasting"
Thanks for the responses by the way..

I did get a response from support on the ## operator.. it went something like:

"Unfortunately ROBOTC preprocessor does not support the "token pasting" (##) operator. This is the first request/ticket on this this in four years. I understand your application and it is a valuable feature. It will get added for a future release."

So.. maybe sometime in the future :-).

so:
for the first question..
If I have a function:
void do(int a, int b)
{
return a+b;
}

=====
Although this doesn't specifically define any "local" variables, one might consider the function arguments (int a, int b) as implicit local variables.
So... the question was really whether a and be are actually passed on the stack or are they really just a couple more Local variables in global space?

( and, really, I should just try this to see if it works.. but forums are much more fun)

The difference can be significant since if they are on the stack, it would allow for locking / synchronization of the code inside a function rather than outside..

thanks again
--marcel


Sun Nov 21, 2010 12:40 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3165
Location: Rotterdam, The Netherlands
Post Re: macro preprocessor and token "pasting"
Marcel,

The arguments thing is a very good question. I will ask the devs, this could have significant on one of my drivers.

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


Sun Nov 21, 2010 3:19 am
Profile WWW
Expert

Joined: Mon Mar 15, 2010 4:24 pm
Posts: 124
Post Re: macro preprocessor and token "pasting"
nanoplane wrote:
If I have a function:
void do(int a, int b)
{
return a+b;
}

=====
Although this doesn't specifically define any "local" variables, one might consider the function arguments (int a, int b) as implicit local variables.
So... the question was really whether a and be are actually passed on the stack or are they really just a couple more Local variables in global space?


In a related question, is there any way to display the function parameters in the debugger? When I display global variables, I see all global and local variables, but not the function parameters. If I display the call stack, I only see the functions called.

I wonder if this is related to having to use "inline" if a function is called from two tasks? Maybe the parameters aren't really on a stack?

cu,
Gary


Mon Nov 22, 2010 7:19 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3165
Location: Rotterdam, The Netherlands
Post Re: macro preprocessor and token "pasting"
Very nice idea. I tend to use a different approach in my driver suite but it also helps with the debugging. The function name prefix is a great idea though. I may end up stealing that idea from you for my next drivers.

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


Tue Feb 14, 2012 2:37 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 10 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.