CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Token concatenation in #define statement containing the (.)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
logicchild



Joined: 16 Nov 2013
Posts: 14

View user's profile Send private message

Token concatenation in #define statement containing the (.)
PostPosted: Sun Jan 12, 2014 10:31 am     Reply with quote

Hi,

I want to write a macro that performs the following:

Code:

#define PORT_PIN(__x,__y) __x##.F##__y


so, when calling it with:

Code:

#define LEDS PORTB
#define LED1 0
PORT_PIN(LEDS, LED1) = 1;


the last line should be:

Code:

PORTB.F0 = 1;


but I get error that says it is "No a valid preprocessing token..."

please help
Code:
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 12, 2014 2:57 pm     Reply with quote

Quote:
the last line should be:

PORTB.F0 = 1;

Your desired output is MikroC code:
http://www.mikroe.com/forum/viewtopic.php?f=13&t=25027
The output of your macro (if it worked) will not compile on CCS,
because CCS doesn't accept MikroC-specific code. Why did you post
this question on the CCS forum ? It's a question for the MikroC forum.
logicchild



Joined: 16 Nov 2013
Posts: 14

View user's profile Send private message

It is How to
PostPosted: Mon Jan 13, 2014 3:00 am     Reply with quote

Hi,

Thanks for the reply.

The idea is that I want to concatenate the token that contains the (.) period char. regardless of what language that I use!
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

Re: It is How to
PostPosted: Mon Jan 13, 2014 3:43 am     Reply with quote

logicchild wrote:
The idea is that I want to concatenate the token that contains the (.) period char. regardless of what language that I use!


You always need to be aware of the capabilities and limitations of specific implementation of any language.

In this case CCS C does not have a full spec. preprocessor. It is limited and does not do some things like concatenation and stringization nor can it split or slice tokens. Neither is it possible to view the output of the pre-processor. It appears that the the pre-processing is not a separate step as has been traditional in C, instead it appears to be just a text process done in-line during compilation.

The simple answer is CCS C won't do what you want, and begs the question why you need this particular functionality.
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Mon Jan 13, 2014 4:32 am     Reply with quote

Actually the CCS preprocessor, does do catenation fine.
However his output, is MicroC instructions, which can't work with CCS.
CCS won't accept the port reference with '.', unless you have declared a structure to make this work, hence the failure.
For instance:
Code:

struct bits
{
   int b0:1;
   int b1:1;
   int b2:1;
   int b3:1;
   int b4:1;
   int b5:1;
   int b6:1;
   int b7:1;
};
struct bits PORTA,PORTB;

#byte PORTA = getenv("SFR:PORTA")
#byte PORTB = getenv("SFR:PORTB")

#define bit_ref(PNUM, bit) PORT##PNUM.b##bit

void main()
{
   bit_ref(A,2)=1;
   while(TRUE)
   {
      //Something
   }
}

Because I have generated the 'dotable' references, this then accesses PORTA.B2

Best Wishes
jeremiah



Joined: 20 Jul 2010
Posts: 1345

View user's profile Send private message

PostPosted: Mon Jan 13, 2014 8:53 am     Reply with quote

yeah, I've been using a lot of those pre processor features for a while now. I won't say they are bug free, but they work for what I have been doing for the last few years.

I agree with Ttelmah in that this is a MikroC trying to be used in CCS issue.
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Mon Jan 13, 2014 9:11 am     Reply with quote

It was PCM, who pointed out the problem first... Smile

They key though is understanding that it is not the catenation that is the problem, but the syntax of the result. Using '.' to access a bit, is not standard C. It can be adapted, by creating bitfields as I show.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group