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

Strange push stack problem [SOLVED]

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



Joined: 08 Jan 2018
Posts: 59
Location: Finland

View user's profile Send private message

Strange push stack problem [SOLVED]
PostPosted: Mon Dec 05, 2022 2:50 am     Reply with quote

Hello i have very strange problem if i use both "push stack" in same time.
If only one of these stack is in use there is no problem, but if they are used in same time only one works..

Code:

//user defines:
#define TEMPELEMENTS                  24         //24h- memory (outdoor)
#define TEMPELEMENTSIN                  24         //24h- memory (indoor)
#define PRINTTMPPUSHSTACK               HW_UART2

//outdoor globals
float temp_stackbuffer[TEMPELEMENTS]={0.0};
//functions:
void temperature_push_stack(float val);
void print_temperature_push_stack(void);      
void clear_temperature_push_stack(void);

//indoor globals
float temp_stackbuffer_indoor[TEMPELEMENTSIN]={0.0};
//functions:
void temperature_push_stack_indoor(float val_in);
void print_temperature_push_stack_indoor(void);      
void clear_temperature_push_stack_indoor(void);


//----------------------------------------------------------
//indoor push data to stack
//----------------------------------------------------------
void temperature_push_stack_indoor(float val_in)
{
   for(byte cc_=TEMPELEMENTSIN;cc_>0;cc_--) 
       temp_stackbuffer_indoor[cc_]=temp_stackbuffer_indoor[cc_-1];

temp_stackbuffer_indoor[0]=val_in;
}

//----------------------------------------------------------
//indoor print it out
//----------------------------------------------------------
void print_temperature_push_stack_indoor(void)
{
byte tmp__=1;
fprintf(PRINTDSTEMP,"\n\rIndoor temperatures (24h) %3ldd:%02d:%02d:%02d",totaldays,totalhours,totalmins,seconds);
   for(byte ii_=0;ii_<TEMPELEMENTSIN;ii_++)
      fprintf(PRINTDSTEMP,"\n\r(-%uh):%.1fc",tmp__++,temp_stackbuffer_indoor[ii_]);
}

//----------------------------------------------------------
//indoor clear it
//----------------------------------------------------------
void clear_temperature_push_stack_indoor(void)
{
memset(temp_stackbuffer_indoor, 0.0, TEMPELEMENTSIN);   
}

//outdoor
//----------------------------------------------------------
void temperature_push_stack(float val)
{
   for(byte c_=TEMPELEMENTS;c_>0;c_--) 
       temp_stackbuffer[c_]=temp_stackbuffer[c_-1];

temp_stackbuffer[0]=val;
}

//outdoor
//----------------------------------------------------------
void print_temperature_push_stack(void)
{   
byte tmp_=1;
fprintf(PRINTDSTEMP,"\n\rOutdoor temperatures (24h) %3ldd:%02d:%02d:%02d",totaldays,totalhours,totalmins,seconds);
   for(byte ii=0;ii<TEMPELEMENTS;ii++)
      fprintf(PRINTDSTEMP,"\n\r(-%uh):%.1fc",tmp_++,temp_stackbuffer[ii]);
}

//outdoor
//----------------------------------------------------------
void clear_temperature_push_stack(void)
{
memset(temp_stackbuffer, 0.0, TEMPELEMENTS);   
}


PCWHD 5.092 + MPLAB IDE 8.92 + plugin for MPLAB IDE
OS WIN10/64bit

Can somebody help, because i cannot locate where the problem is?


Last edited by -Terppa- on Mon Dec 05, 2022 1:08 pm; edited 1 time in total
-Terppa-



Joined: 08 Jan 2018
Posts: 59
Location: Finland

View user's profile Send private message

PostPosted: Mon Dec 05, 2022 4:00 am     Reply with quote

Hmmm.. it seems to work if i add "dummy" line

Code:

float temp_stackbuffer_indoor[TEMPELEMENTSIN]={0.0};
float dummy[1]={0.0}; //added dummy line
float temp_stackbuffer[TEMPELEMENTS]={0.0};
temtronic



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

View user's profile Send private message

PostPosted: Mon Dec 05, 2022 6:01 am     Reply with quote

Does CCS C consider both 'push' and 'stack' to be reserved words and cannot be used ,in your case as variables?

I know BASIC always had an appendix that listed 'reserved words' that you could not use

I'm thinking that when the compiler attempts to parse a line it sees push, stack and says 'error', however when it's got =0.0; on the end, it now KNOWS that the item on the left side is a variable.

I'm sure one of the C experts here know HOW the compiler figures this stuff out and can explain it
-Terppa-



Joined: 08 Jan 2018
Posts: 59
Location: Finland

View user's profile Send private message

PostPosted: Mon Dec 05, 2022 6:42 am     Reply with quote

Thank you for your reply Mr.Temtronic.
I always try to avoid using reserved words.

I'm little bit confusing because now i have same functions and that added dummy float and now both buffers seems to work Rolling Eyes

I think it is not the proper way to do that..
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Dec 05, 2022 7:23 am     Reply with quote

I suspect it does not like having an 'array' initialisation with only one element.
The dummy, may be tricking it into accepting this.
-Terppa-



Joined: 08 Jan 2018
Posts: 59
Location: Finland

View user's profile Send private message

PostPosted: Mon Dec 05, 2022 7:35 am     Reply with quote

Thank you Mr.Ttelmah

I tested in this way:
Code:

float temp_stackbuffer_indoor[TEMPELEMENTSIN]={};
float temp_stackbuffer[TEMPELEMENTS]={};


and it stop working again. (only temp_stackbuffer gets values)
but when it is this way it works:

Code:

float temp_stackbuffer_indoor[TEMPELEMENTSIN]={};
float dummy__[1]={0.0};
float temp_stackbuffer[TEMPELEMENTS]={};
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Dec 05, 2022 12:11 pm     Reply with quote

The problem is the code is overflowing the stack. Having the dummy
variable allows this to not overwrite the next variable,

For example:
Code:

   for(byte c_=TEMPELEMENTS;c_>0;c_--) 
       temp_stackbuffer[c_]=temp_stackbuffer[c_-1];


c_ is set to 24. So the first time round, this writes to element 24.
The array only has elements 0 to 23.

It looks as if possibly you have taken this code from a language that
has 1 as the first array element.
-Terppa-



Joined: 08 Jan 2018
Posts: 59
Location: Finland

View user's profile Send private message

PostPosted: Mon Dec 05, 2022 1:07 pm     Reply with quote

Thats is! Thank you very much! Or how finnish people says: Paljon kiitoksia
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