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

Printf is too long? Complex?

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



Joined: 03 Aug 2009
Posts: 995
Location: Panama

View user's profile Send private message

Printf is too long? Complex?
PostPosted: Tue Jun 11, 2019 9:02 pm     Reply with quote

Hi All,

I got this error:

Quote:
Line 148(24,31): Expression too complex


Its on a print statement that's printing 14 floats and 9 ints but these are elements in an array of structs.
I do get this is a long print and that i might be pushing it.

Ive solved it by printing in 2 stages but since all, except for the "Index" which is not part of the struct, this is exactly 64 bytes or half a page... so i would really like to do this in one print.

Is this error normal?
Version 5.013 since 5.078 still gives me the endif error and this code is a spin off from that particular code from one of my last posts.



Code:
      fprintf(lcd_putc,"EEPROM LOG#%u: %3.2f,%3.2f,%3.2f,%3.2f,%3.2f,%3.2f,%3.2f,%3.2f,%3.2f,%3.2f,%3.2f,%3.2f,%3.2f,%3.2f,%u,%u,%u-%u-%u/%u:%u:%u\r\n",
      Temp_Index,
      Log_Buffer[Temp_Index].DP_Value1,      
      Log_Buffer[Temp_Index].DP_Value2,
      Log_Buffer[Temp_Index].DP_Value3,   
      Log_Buffer[Temp_Index].DP_Value4,   
      Log_Buffer[Temp_Index].DP_Value5,   
      Log_Buffer[Temp_Index].DP_Value6,
      Log_Buffer[Temp_Index].DP_Value7,
      Log_Buffer[Temp_Index].DP_Value8,
      Log_Buffer[Temp_Index].DP_Value9,   
      Log_Buffer[Temp_Index].DP_Value10,   
      Log_Buffer[Temp_Index].DP_Value11,
      Log_Buffer[Temp_Index].DP_Value12,
      Log_Buffer[Temp_Index].DP_Value13,   
      Log_Buffer[Temp_Index].DP_Money,
                        
      Log_Buffer[Temp_Index].DP_STATUS_BYTE,
      Log_Buffer[Temp_Index].DP_BLANK,
         
      Log_Buffer[Temp_Index].DP_YEAR,
      Log_Buffer[Temp_Index].DP_MONTH,
      Log_Buffer[Temp_Index].DP_DAY,
      Log_Buffer[Temp_Index].DP_HOUR,         
      Log_Buffer[Temp_Index].DP_MINUTES,
      Log_Buffer[Temp_Index].DP_SECONDS);

_________________
CCS PCM 4.135 & CCS PCH 5.013
Ttelmah



Joined: 11 Mar 2010
Posts: 14440

View user's profile Send private message

PostPosted: Wed Jun 12, 2019 12:30 am     Reply with quote

Honestly, why not have the DP.values as an array?.
There is no disadvantage at all in using multiple printf's, rather than one,
and it'd be more efficient in code size, and handling to just use:
Code:

fprintf(lcd_putc,"EEPROM LOG#%u: ", Temp_Index);
for (count=1;count<14;count++)
    fprintf(lcd_putc,"%3.2f,", Log_Buffer[Temp_Index].DP_Value[count]);

This will be about 1/10th the actual size in terms of the code, to the
single printf.
You could also cheat if you don't want to re-declare the variable, by using
#locate, to put a second array variable into the same memory location.

There is a limit in printf, on the maximum length of the format string. I think
if I remember correctly, it is somewhere just over 100 bytes. This is what
you are hitting.
Gabriel



Joined: 03 Aug 2009
Posts: 995
Location: Panama

View user's profile Send private message

PostPosted: Wed Jun 12, 2019 7:42 am     Reply with quote

Thanks for the Array idea!
I could extend that to the other ints too.

So an array of structs, with each struct containing 2 arrays, 1 for 14 floats and the other 8 ints.

I like it... now ill have to see how this configuration affects the rest of the code.

but i do like it!

Thanks for this unexpected sugestion!
_________________
CCS PCM 4.135 & CCS PCH 5.013
temtronic



Joined: 01 Jul 2010
Posts: 6704
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jun 12, 2019 8:19 am     Reply with quote

Yes, there is a limit, I found that out years ago....I use multiple lines, easier to keep track of individual items and easy to edit the 'format' of them as well.

Jay
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