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