![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
avacore
Joined: 04 Jul 2011 Posts: 2
|
Output of the preprocessor |
Posted: Mon Jul 04, 2011 9:24 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19359
|
|
Posted: Mon Jul 04, 2011 3:03 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
avacore
Joined: 04 Jul 2011 Posts: 2
|
|
Posted: Wed Jul 06, 2011 3:49 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19359
|
|
Posted: Wed Jul 06, 2011 3:51 am |
|
|
What if you add the line rollover character '\'?.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|