Jump to content

Problem With Function Overloading


Recommended Posts

Environment: Sourceboost 5.8 BoostC 1.9

OS: XP sp2

PIC: 16F877a

 

Compile and debug this code only the first send in main() works.

 

 

#include <system.h>

 

rom char *msg = "Message";

 

void send(const char c)

{

char b = c;

}

 

void send(const char* s)

{

while (*s)

send(*s++);

}

 

void main()

{

send ('a');

send ("Test");

send (msg);

}

Link to post
Share on other sites

Try to edit your code to look more like:

 

#include <system.h>

rom char *msg = "Message";

void send(const char c)
{
   char b = c;
}

void send(rom char* s)
{
}

void main()
{
   send ('a');
   send ((rom char*)"Test");
   send (msg);
}

 

 

Regards,

Pavel

Link to post
Share on other sites
Try to edit your code to look more like:

 

#include <system.h>

rom char *msg = "Message";

void send(const char c)
{
   char b = c;
}

void send(rom char* s)
{
}

void main()
{
   send ('a');
   send ((rom char*)"Test");
   send (msg);
}

 

 

Regards,

Pavel

Pavel,

 

I changed my code to

 

 

void send(rom char* s)

{

while (*s)

send(*s++);

}

 

now i've got a compilation error

 

error invalid operation applied to operand with 'rom' storage type.

 

when I change my code to

 

void send(rom char* s)

{

char i = 0;

while(s)

{

send(s);

i++;

}

}

 

it works fine, but why can't I use pointers ?

 

Frank

Link to post
Share on other sites

FrankGe,

 

I would recommend code the function this way:

 

void send(rom char* s)
{
char c;
char i = 0;

while ( c = s[ i ] )
{  
 send(c);
 i++;
}
}

 

This only computes and use once the index value, making the code length much shorted.

 

Regards

Dave

Link to post
Share on other sites

Pavel, Dave,

 

I've got now a new project without "rom char * "

 

but it doesn't work

 

#include <system.h>

 

void send(char c)

{

char b = c;

}

 

 

void send(char* s)

{

char c;

char i = 0;

while(c = s)

{

send©;

i++;

}

}

 

void main()

{

while (1)

{

send ('a');

send ("Test");

}

}

 

Frank.

Link to post
Share on other sites

You've absolulutly right, this does appear to be a bug.

 

I used the simulator to test your code and both send(..) calls routed to the single char option.

 

However, changing your send calls like this:

 

send ('a');

send ( (char*) "Test" );

 

makes it work for now until this bug is fixed.

 

 

 

 

joe

Link to post
Share on other sites
You've absolulutly right, this does appear to be a bug.

 

I used the simulator to test your code and both send(..) calls routed to the single char option.

 

However, changing your send calls like this:

 

send ('a');

send ( (char*) "Test" );

 

makes it work for now until this bug is fixed.

 

 

 

 

joe

 

Fixed in BoostC 1.9.2

 

Regards,

Pavel

Link to post
Share on other sites

Hello,

 

OS: XP SP2

Sourceboost 5.8

BOOSTC 1.9.2

 

There is still a problem with "rom char *"

 

#include <system.h>

 

rom char *msg = "Message";

 

void send(const char c)

{

char b = c;

}

 

void send(const char* s)

{

char c;

char i = 0;

while(c = s)

{

send©;

i++;

}

}

 

void main()

{

while (1)

{

send ('a');

send ("Test");

send (msg);

}

}

 

When I have to cast to "rom char *" I think the compiler should give me an error.

because it doesn't work.

 

Frank

Link to post
Share on other sites
...

When I have to cast to "rom char *" I think the compiler should give me an error.

because it doesn't work.

 

Did you want to say "cast from 'rom char*' to 'const char*'"? I don't think compiler should trow an error for such conversions (some general come may for example store rom pointer in a variable) however a warning for such conversion may be a good idea.

 

Regards,

Pavel

Link to post
Share on other sites
The last example doesn't work. The function send(msg) does nothing. Look with the debugger.

 

Of course it won't work. A 'rom' pointer casted to non-rom can't be used anymore unless it gets casted back to 'rom' type.

 

Regards,

Pavel

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...