XCSB support function overloading. This means that the user can define several functions all having the same name but different behaviour.The compiler differentiates the functions by their parameters. This means that if several functions called FRED are defined, then the compiler identifies which exact function to use by the actual parameters that are used with the function.
without function overloading
proc print_byte(byte arg) endproc proc print_int(int arg) endproc proc print_long(long arg) endprocwith function overloading
proc print(byte arg) // AAA endproc proc print(int arg) // BBB endproc proc print(long arg) // CCC endprocexample of use
proc main() byte a1 int b1 long c1 print(a1) // invokes AAA print(b1) // invokes BBB print(c1) // invokes CCC endprocWhy bother?In the above example it would be simple to define one function that can deal with all integers by simply defining its parameter as a long. However this has a huge drawback, whenever it is used any parameter supplied is promoted to long which is very inefficient if the function is only ever used with parameters of type byte or int.
Elegant Solutions To Complex Problems
One big problem on the PIC is the distinction between the CODE and DATA space. This means that pointers either need to be built to handle both address spaces simultaniously and handled specially (and inefficiently) at runtime or the compiler needs to be able to handle two differnt types of pointers and generate special static (efficient) code to deal with them at compile time.Overloaded functions allow this to be done in a very elegant way.
e.g.
proc print(char *) endproc proc print(char * const) endproc