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 support@ccsinfo.com

Output of the preprocessor

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



Joined: 04 Jul 2011
Posts: 2

View user's profile Send private message

Output of the preprocessor
PostPosted: Mon Jul 04, 2011 9:24 am     Reply with quote

First the question: Is it possible to get the CCS Compiler to dump the output after preprocessing, much like GCC's -E switch?

Now some background: I'm trying to use the preprocessor to generate some portions of code. Currently my code looks as follows:
Code:
#define SENSOR_SENS_TYPE_INT( type, pre, sample, read, post ) type
#define SENSOR_SENS_TYPE( sens ) SENSOR_SENS_TYPE_INT sens
#define SENSOR_SENS_PRE_INT( type, pre, sample, read, post ) pre
#define SENSOR_SENS_PRE( sens ) SENSOR_SENS_PRE_INT sens
#define SENSOR_SENS_SAMPLE_INT( type, pre, sample, read, post ) sample
#define SENSOR_SENS_SAMPLE( sens ) SENSOR_SENS_SAMPLE_INT sens
#define SENSOR_SENS_READ_INT( type, pre, sample, read, post ) read
#define SENSOR_SENS_READ( sens ) SENSOR_SENS_READ_INT sens
#define SENSOR_SENS_POST_INT( type, pre, sample, read, post ) post
#define SENSOR_SENS_POST( sens ) SENSOR_SENS_POST_INT sens

#define SENSOR( id, name, sens, config, housekeep, test ) \
SENSOR_SENS_TYPE( sens ) gen_sensor_read_ ##name() { \
   SENSOR_SENS_TYPE( sens ) val; \
   SENSOR_SENS_PRE( sens ); \
   delay_ms( SENSOR_SENS_SAMPLE( sens ) ); \
   val = SENSOR_SENS_READ( sens ); \
   SENSOR_SENS_POST( sens ); \
   return val; \
}

SENSOR(
   TEST_SENSOR, test,
   ( int16, pre_func(), sample_func(), read_func(), post_func() ),
   /* Configuration info will go here */,
   /* Housekeeping info will go here */,
   /* Test info will go here */
)

The goal is to generate the following code.
Code:
int16 gen_sensor_read_test() {
    int16 val;
    pre_func();
    delay_ms(sample_func());
    val = read_func();
    post_func();
    return val;
}

GCC is able to produce this (as a matter of fact, the above is the indented output of GCC's preprocessor), however the CCS compiler errors out on the macros, mainly complaining that "Macro identifier requires parameters" referring to the invocation of the *_INT macros.
Ttelmah



Joined: 11 Mar 2010
Posts: 19249

View user's profile Send private message

PostPosted: Mon Jul 04, 2011 3:03 pm     Reply with quote

No. On most C's, the preprocessor is a separate module. It is not on CCS.
However the defines look very strange. It appears the preprocessor you are using, is accepting token sequence values passed without the brackets, and also not requiring the sequence passed to match the size of the sequence defined. CCS, keeps to the original K&R standard, and does require both of these.

I'd suggest you try your code with the -std, and -pedantic switches. This will be closer to what CCS expects.

Best Wishes
avacore



Joined: 04 Jul 2011
Posts: 2

View user's profile Send private message

PostPosted: Wed Jul 06, 2011 3:49 am     Reply with quote

Ok, I just played around with this some more. Apparently CCS is somewhat picky about newlines when using the macros. The following invocation works:
Code:
SENSOR( TEST_SENSOR, test, ( int16, pre_func(), sample_func(), read_func(), post_func() ), /* Configuration info will go here */, /* Housekeeping info will go here */, /* Test info will go here */ )

While to original multi line one does not.
Ttelmah



Joined: 11 Mar 2010
Posts: 19249

View user's profile Send private message

PostPosted: Wed Jul 06, 2011 3:51 am     Reply with quote

What if you add the line rollover character '\'?.

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