We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I have a function,but the compiler terminated because the function is too complex.
C51 FATAL-ERROR - ACTION: GENERATING INTERMEDIATE CODE ERROR: FUNCTION '_siParseDescriptor' (LINE 1058, T=400,L=132,l=1): TOO COMPLEX C51 TERMINATED.
make it simpler, then!
another case of PCitis? Erik
Mike, Can you post the offending function? Stefan
"Can you post the offending function?" Is that going to be practical, given that it's so complicated that it breaks the compiler!!??
Make sure you have matched braces, parnthesis, and semicolons !
...... CreateSatelliteDeliverySystemDescriptor (Descriptor, BcdCharToInt (sds->frequency1) * 10L * 1000 * 1000 + BcdCharToInt (sds->frequency2) * 100L * 1000 + BcdCharToInt (sds->frequency3) * 1000L + BcdCharToInt (sds->frequency4) * 10, (sds->west_east_flag ? 1 : -1) * (BcdCharToInt (sds->orbital_position1) * 100 + BcdCharToInt (sds->orbital_position2)), sds->modulation, sds->polarization, BcdCharToInt (sds->symbol_rate1) * 10L * 1000 + BcdCharToInt (sds->symbol_rate2) * 100L + BcdCharToInt (sds->symbol_rate3), sds->fec_inner); ......
struct SatelliteDeliverySystemDescriptor { struct NODE Node; uint16_t Tag; long Frequency; short OrbitalPosition; short Modulation; char Polarization; long SymbolRate; char FEC; }; #define CreateSatelliteDeliverySystemDescriptor(descr, freq, orb, mod, polar, sr, fec) do { xCreateNode (((struct SatelliteDeliverySystemDescriptor *)descr), NULL); ((struct SatelliteDeliverySystemDescriptor *)descr)->Tag = DESCR_SAT_DEL_SYS; ((struct SatelliteDeliverySystemDescriptor *)descr)->Frequency = freq; ((struct SatelliteDeliverySystemDescriptor *)descr)->OrbitalPosition = orb; ((struct SatelliteDeliverySystemDescriptor *)descr)->Modulation = mod; ((struct SatelliteDeliverySystemDescriptor *)descr)->Polarization = polar; ((struct SatelliteDeliverySystemDescriptor *)descr)->SymbolRate = sr; ((struct SatelliteDeliverySystemDescriptor *)descr)->FEC = fec; } while (0)
#define BcdCharToInt(x) (10*((x & 0xF0)>>4) + (x & 0xF))
...... long freq = BcdCharToInt (sds->frequency1) * 10L * 1000 * 1000 + BcdCharToInt (sds->frequency2) * 100L * 1000 + BcdCharToInt (sds->frequency3) * 1000L + BcdCharToInt (sds->frequency4) * 10; long srate = BcdCharToInt (sds->symbol_rate1) * 10L * 1000 + BcdCharToInt (sds->symbol_rate2) * 100L + BcdCharToInt (sds->symbol_rate3); CreateSatelliteDeliverySystemDescriptor (Descriptor, freq, (sds->west_east_flag ? 1 : -1) * (BcdCharToInt (sds->orbital_position1) * 100 + BcdCharToInt (sds->orbital_position2)), sds->modulation, sds->polarization, srate, sds->fec_inner); ......
CreateSatelliteDeliverySystemDescriptor (Descriptor, BcdCharToInt (sds->frequency1) * 10L * 1000 * 1000 + BcdCharToInt (sds->frequency2) * 100L * 1000 + BcdCharToInt (sds->frequency3) * 1000L + BcdCharToInt (sds->frequency4) * 10, (sds->west_east_flag ? 1 : -1) * (BcdCharToInt (sds->orbital_position1) * 100 + BcdCharToInt (sds->orbital_position2)), sds->modulation, sds->polarization, BcdCharToInt (sds->symbol_rate1) * 10 * 1000 + BcdCharToInt (sds->symbol_rate2) * 100 + BcdCharToInt (sds->symbol_rate3), sds->fec_inner);
Maybe the macro expansion is going wrong due to insufficient or misplaced parentheses? If the preprocessor output file is generated before you get the error you might be able to spot what's going wrong, but I doubt it - it'll probably be incomprehensible. Do you have to use macros? Much less confusing to use functions. Stefan
That code has just about broken the forum never mind the compiler. Took me ages to find the post button. Stefan
For starters, I think you should get rid of all those casts. They're either superfluous or dangerous, but they're quite certainly not going to help you with anything. I second the suggestion that you really should turn this initializer macro into a function. All those BcdCharToInt() results multiplied with powers of ten strongly suggest you're doing yourself a disfavour in that area, too. You need a Bcd4CharsToInt(), and it should be function, not a macro. Putting it all together, you're abusing macros, to the point of overstressing the compiler. [Error message...] But it doesn't seem to apply to the above code. What ever made you think it didn't? Get yourself a preprocessor listing for this source file, open it in an editor window, look at it, and then say that again...
Take a look at Andy's Handy Hint for Debugging Preprocessor Problems: http://www.8052.com/forum/read.phtml?id=29152 Note that the preprocessor listing is itself a 'C' source file - so you can get the compiler to compile it. This might pinpoint the error a bit more closely?
I suspect the problem is just the complexity of that huge, huge, expression. When you introduce the intermediate variables, you simply the amount of code in one chunk, which I imagine is why the code starts to compile. What's the purpose of the "do {} while(0)" in your create macro? Simple curly braces should work as well to introduce a local block. Also, just as a readability and style nitpick, complicated macros are probably better defined using the backslash to allow them to occupy multiple lines.
#define CreateSatelliteDeliverySystemDescriptor(descr, freq, orb, mod, polar, sr, fec) { xCreateNode (((struct SatelliteDeliverySystemDescriptor *)descr), NULL); ((struct SatelliteDeliverySystemDescriptor *)descr)->Tag = DESCR_SAT_DEL_SYS; ((struct SatelliteDeliverySystemDescriptor *)descr)->Frequency = freq; ((struct SatelliteDeliverySystemDescriptor *)descr)->OrbitalPosition = orb; ((struct SatelliteDeliverySystemDescriptor *)descr)->Modulation = mod; ((struct SatelliteDeliverySystemDescriptor *)descr)->Polarization = polar; ((struct SatelliteDeliverySystemDescriptor *)descr)->SymbolRate = sr; ((struct SatelliteDeliverySystemDescriptor *)descr)->FEC = fec; }
too comples to compile how about "too complex to rtead" Why does "real C" programmers insist on cramming more than a human can understand into a single statement. As far as I can see this can easiy be broken up in 4-10 understandable statements. Is there really a reason to make it as tough as posssible on the next guy/gal assigned maintenance of the code? Erik
"What's the purpose of the "do {} while(0)" in your create macro? Simple curly braces should work as well to introduce a local block." Not quite. Consider the use of a function-like macro (i.e., terminated with a semicolon) in an if/else clause expanding to the curly brace from only. Please refer to: http://www.eskimo.com/~scs/C-faq/q10.4.html The do/while(0) method is the safe way to define a function-like (multi-statement) macro.