Jump to content

Boostc Complier Problem


Recommended Posts

The following code produces the linker error: "target call stack depth of 8 exceeded"

 

#include <system.h>
void sub(char y)
{
}
void sub(unsigned long X)
{
sub('x'+X/257);
}
void main()
{
sub(10000);		
}

 

If the name of one of the subroutines is changed, the code works; If the 'X/257' in line 7 is removed, the code works.

 

BoostLink V 6.4

BoostC V6.4

MPLAB IDE

PIC16F917

Link to post
Share on other sites

bgamberg,

 

The following code produces the linker error: "target call stack depth of 8 exceeded"

 

#include <system.h>
void sub(char y)
{
}
void sub(unsigned long X)
{
    sub('x'+X/257);
}
void main()
{
    sub(10000);        
}

 

If the name of one of the subroutines is changed, the code works;  If the 'X/257' in line 7 is removed, the code works.

 

BoostLink V 6.4

BoostC V6.4

MPLAB IDE

PIC16F917

This is not a bug!

You are using overloaded functions, the passed argument is type char the first function is called. When the passed argument type is bigger than a char then the second function is called.

By adding the x/257 you are promoting the value of the expression from char to int (because 257 is greater than the value a char can hold), so the second function gets called.

 

To fix your code cast the result back to a char:

#include <system.h>
void sub(char y)
{
}
void sub(unsigned long X)
{
   sub((char)('x'+X/257) );
}
void main()
{
   sub(10000);        
}

Regards

Dave

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...