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 CCS Technical Support

Phantom Function calls
Goto page 1, 2, 3  Next
 
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: 1067
Location: Panama

View user's profile Send private message

Phantom Function calls
PostPosted: Mon Apr 01, 2019 12:32 pm     Reply with quote

Hi, I have a Gigantic project, many thousands of lines of code, and I'm getting into a strange situation.

I'm getting phantom function calls.

For example, a particular section of code runs and out of nowhere an unrelated function gets called. So far its always the same function. I can repeat the error by making the device run certain code paths with obviously do not involve calling the phantom function.

Fortunately the phantom function call is pretty benign, the only "real" consequence is a slight delay, since this function needs to execute.
But I need to solve this.

I have seen weird errors like this due to too many int1 variables, but in this particular case i believe its due to a particular long function in my main .C file. I believe this particular function might be stepping over some memory boundary and the compiler is having a fit. How can i check?

This gigantic function is a huge switch statement with is responsible for "typing" text messages (different kinds of alerts, errors, etc), but i have over 20 cases with multiple printf statements each case.

So, any suggestions on what could be causing phantom calls or how can i reduce a switch with many cases?

Thanks
G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Mon Apr 01, 2019 12:49 pm     Reply with quote

How many cases?.

Honestly 5.013, is a very early V5 compiler before several bugs
were fixed.
If you have no 'default' case, and the cases are sequential on a
PIC16 or 18, the switches should code as a jump table. With 5.013
it is possible you are experiencing a page switch problem from the
jump table.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 01, 2019 1:03 pm     Reply with quote

Download the CCS demo. Presumably it's the latest version, or near to it.
See if you still get the problem. If not, then upgrade. Or buy the 1-year
maintenance if they allow you to.
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Apr 01, 2019 1:08 pm     Reply with quote

17 actually coded (its a work in progress) + Default case.
Cases in this switch are controlled by a single int with values 1 - 35
cases 1-14 are coded, then a jump to cases 20-21 + Default.
to be clear i have not defined cases 15-20.


I have sitting a folder 5.078 which i have not installed because i said i was not going to update until i finished this project because i didnt want to deal with any possible bugs from the compiler change... also because i forgot how to update.

I really appreciate your help.
_________________
CCS PCM 5.078 & CCS PCH 5.093
dluu13



Joined: 28 Sep 2018
Posts: 395
Location: Toronto, ON

View user's profile Send private message Visit poster's website

PostPosted: Mon Apr 01, 2019 1:22 pm     Reply with quote

ah... I'm on 5.082, and I have had some of these "phantom" bits of code that get executed. I was confused, but I never looked into it though...

I just changed them to int8 0's and 1's and then stopped having issues.

I know this is off topic, but why are the int1's misbehaving?
temtronic



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

View user's profile Send private message

PostPosted: Mon Apr 01, 2019 1:30 pm     Reply with quote

Quick, easy test...
I'd define all of those undefined cases. Just some 'nop' do nothing code but fill the table... they become 'place holders' that organise the 'code' And... presumably you'll need them in the near future...
IF the phantom menace goes away, you've got your answer. If not, well, you've eliminated it as being the cause.

As for int1 misbehaving.. I think I read somewhere, long, long time ago it's best to put 8 int1s into an int8. If you need 7 int1, add a dummy int1 to fill a byte.

Jay
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Apr 01, 2019 1:32 pm     Reply with quote

Quote:
I think I read somewhere, long, long time ago it's best to put 8 int1s into an int8. If you need 7 int1, add a dummy int1 to fill a byte.


This worked for me when i had this issue.

I will update to 5.078 and see what happens.
_________________
CCS PCM 5.078 & CCS PCH 5.093
PrinceNai



Joined: 31 Oct 2016
Posts: 480
Location: Montenegro

View user's profile Send private message

PostPosted: Mon Apr 01, 2019 1:48 pm     Reply with quote

I never liked those int1-s. Not because I had any problems with them, but for me it is way easier to check for a value of a flag with debugger if it is declared as int8. I'd only use them if I'd need every byte of RAM, which for my projects isn't an issue at all.
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Apr 01, 2019 2:16 pm     Reply with quote

So I updated to 5.078.

I now get an error saying im missing an "#ENDIF" at the bottom of my main C file... im not.

ive added the endif just to see what happens and i get an error over a commented out block of code.

sigh... this is why i didnt want to update.
_________________
CCS PCM 5.078 & CCS PCH 5.093
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Apr 01, 2019 2:35 pm     Reply with quote

Reverted back to 5.013 and it compiles just fine.

I did find that 5.078 found an error like this:

Code:
fprintf(lcd_putc"\r\n");


Note missing comma after stream - These have been corrected.

What now?
_________________
CCS PCM 5.078 & CCS PCH 5.093
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 01, 2019 2:42 pm     Reply with quote

I would have corrected the #endif problem.
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Apr 01, 2019 2:46 pm     Reply with quote

PCM_P: that was my first path to resolving this... I have checked all included files for a missing #endif and i cant find it.

Its asking me for an #endif on a blank line after the last line of code.
its also giving me a warning on string.h which i find strange.

Quote:
Executing: "C:\Program Files (x86)\PICC - 5.078\Ccsc.exe" +FH "Heimdall - Test Program.c" +DF +LN +T +A +M +Z +Y=9 +EA #__18F87J50=TRUE
Compiling C:\Users\Foo-Bar\Documents\1. PIC Developement\CCS Compiler\CONASA\CONASA - HEIMDALL\Heimdall - Test Program on 01-abr-19 at 15:40
>>> Warning 236 "C:\Program Files (x86)\PICC - PCH - 5.013\drivers\string.h" Line 54(9,16): Defined identifier matches a variable ID
>>> Warning 230 "C:\Users\Foo-Bar\Documents\1. PIC Developement\CCS Compiler\CONASA\CONASA - HEIMDALL\H-GSM-General Driver-3G.c" Line 660(1,1): String truncated
>>> Warning 203 "C:\Users\Foo-Bar\Documents\1. PIC Developement\CCS Compiler\CONASA\CONASA - HEIMDALL\H-GSM-Amenities-3G.c" Line 74(1,1): Condition always TRUE
*** Error 14 "C:\Users\Foo-Bar\Documents\1. PIC Developement\CCS Compiler\CONASA\CONASA - HEIMDALL\Heimdall - Test Program.c" Line 1624(9,10): Missing #ENDIF
1 Errors, 3 Warnings.
Build Failed.
Halting build on first failure as requested.
BUILD FAILED: Mon Apr 01 15:40:37 2019

_________________
CCS PCM 5.078 & CCS PCH 5.093
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 01, 2019 2:56 pm     Reply with quote

I uninstalled vs. 5.083, and installed vs. 5.078. I then compiled the
following program. It didn't give any errors or warnings.

I'm wondering if you have 5.013 CCS driver files and #include files
copied to your local project folder. Or somehow you are using a mix
of old files and new ones from 5.078.

Test program:
Code:
#include <18F87J50.h>
#fuses NOWDT
#use delay(crystal=20M)

#include <string.h>

//==========================
void main()
{



while(TRUE);
}   
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Apr 01, 2019 3:14 pm     Reply with quote

Quote:
I'm wondering if you have 5.013 CCS driver files and #include files
copied to your local project folder. Or somehow you are using a mix
of old files and new ones from 5.078.


This might explain the string.h warning.

But the #endif is killing me.. ive re-checked all my code.. im not missing one.

The 2 most extreme cases of #IF type of statements i use are as follows:
Code:

#ifdef SUPER_CLICK
   #define ESP_RESET PIN_A1 //Clasic ESP (cheap one)
#else
   #ifdef LEGACY
      #define ESP_RESET PIN_A1 //Original MikroE ESP
   #else
      #define ESP_RESET PIN_D1 //New MikroE ESP
   #endif
#endif


Code:

   #ifdef LEGACY
      if(Find_in_Buffer("OK",20))
   #else
      if(Find_in_Buffer("GOT IP",20))
   #endif
   {
      fprintf(lcd_putc,"WIFI - Connected to Network\r\n");
      WIFI_RESET_FLAG=FALSE;
      return(1);
   }
   else return(0);



This is part of my ESP-8266 driver, to handle older versions of the hardware.

This has worked for the last 4 years...across several projects that share this driver... although it works... ive always felt its ugly code (the IF statement selection)...

I cant find a missing #ENDIF...
_________________
CCS PCM 5.078 & CCS PCH 5.093
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Apr 01, 2019 3:34 pm     Reply with quote

Wait a minute:

Quote:
>>> Warning 236 "C:\Program Files (x86)\PICC - PCH - 5.013\drivers\string.h" Line 54(9,16): Defined identifier matches a variable ID


how do i correct this so that it pulls it from the the newly installed 5.078 folder?
_________________
CCS PCM 5.078 & CCS PCH 5.093
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
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