Jump to content
Sign in to follow this  

Function Return Type Compilation Bug

Recommended Posts

Bug description:

The compiler fails to compile correctly functions with a non void return type that are declared in an external header file and defined in an external source file. It appears to think that a char return is actually a char*, an int an int*, etc


Steps to reproduce:


Create a main source file "main.c"

Create a include file "string.h"

Create a source file "string.c"


Content of "string.h"


char* strchr(char* pszString, char chFind);

char strlen(char* pszString);

char isspacex( char ch );

int atoi(char *nptr);


Content of "string.c"


#include <system.h>

#define null 0



// Returns a ptr to the first occurance of chFind within pszString

// or null if it does not exist


char* strchr(char* pszString, char chFind)


while (*pszString != '\0')


if (*pszString == chFind)

return pszString;



return null;




// Returns the length of a string excluding the terminating null character


int strlen(char* pszString)


int nLen = 0;

while (*pszString != '\0')


return nLen; /* Error (1) reported here */



char isspace( char ch )


char cRet = 0;

if (ch == ' ' || ch == '\n' || ch == '\t' || ch == '\r')

cRet = 1;


return cRet; /* Error (2) reported here */




// Decodes an int from a string


int atoi(char *nptr)


int c; // current char

int total; // current total

int sign; // if '-', then negative, otherwise positive


// skip whitespace

while ( isspace((int)(unsigned char)*nptr) )



c = (int)(unsigned char)*nptr++;

sign = c; /* save sign indication */

if (c == '-' || c == '+')

c = (int)(unsigned char)*nptr++; /* skip sign */


total = 0;


while (isdigit©)


total = 10 * total + (c - '0'); /* accumulate digit */

c = (int)(unsigned char)*nptr++; /* get next char */



if (sign == '-')

total = 0 - total;


return total; /* return result, negated if necessary */ /* Error (3) reported here */



Content of "main.c"


#pragma CLOCK_FREQ 20000000


#include <system.h>

#include "string.h"



// Set the configuration values (aka fuses)

#ifdef _PIC16F876A

// Appropriate defines for 16F877A

#pragma DATA 0x2007, _HS_OSC & _CP_OFF & _DEBUG_OFF & _WRT_OFF & _CPD_OFF & _LVP_ON & _BODEN_ON & _PWRTE_ON & _WDT_OFF



#ifdef _PIC16F877

// Appropriate defines for 16F877A





void main()


char* pszString = "Test";

int nVal = strlen(pszString);





This generates the following build report:


BoostC Optimizing C Compiler Version 1.8 Alpha (for PIC16 architecture)


Copyright© 2004 Pavel Baranov

Copyright© 2004 David Hobday



string.c(27:2): error: can't convert 'signed int' to 'signed int*' (Error 1)

string.c(36:2): error: can't convert 'unsigned char' to 'unsigned char*' (Error 2)

string.c(68:2): error: can't convert 'signed int' to 'signed int*' (Error 3)


Exit code was 1.

Removing target: FunctionReturnBug.obj

Failed to locate output file 'FunctionReturnBug.obj'







Expected behaviour:

The above should compile and link as expected


Is the problem 100% reproduceable:

100% reproduceable. Interestingly if the same functions are defined in the main source file it compiles as expected.


IDE version: SourceBoost IDE version

Compiler: BoostC

Compiler version: 1.8 Alpha

Target device: PIC16F876A

OS: XP Pro SP1




Edited by neilbuck

Share this post

Link to post
Share on other sites
Can you edit your post and mark the lines where errors happen.







I've edited my original post with where the errors are reported. As you can see they are

where strlen(), isspace(), and atoi() return respectively.


Note that strchr() doesn't report an error but I suspect that this has something to do with the fact that it already returns an address (char*).





Share this post

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.

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.

Sign in to follow this  

  • Create New...