Hi, In our project we are using function pointers. After compiling the project, we got "RECURSIVE CALL TO SEGMENT" warning. By selecting OVERLAY (sfname ! *)in BL51, that warnings was removed. If we add function name in OVERLAY, will it allocate diffrent memory for local variables and function argumants?. How it is diffrent from by difining same function as rentrant function ?. Thanks in advance..
So, Which are the functions are being called indirectly(through function pointers)are should be defined using OVERLAY directive. Those that you, by (most likely faulty) human deduction, can figure out can use overlaid local variables. The "(most likely faulty) human deduction" is probably the most compelling reason to avoid function pointers when coding for the '51. There are means, as Jay show abive, to create "function selection friendly to the '51 architcture" so why not use those. That some ingnramus has told you that "C is C" you can file under Urban legends. Erik
If you know which functions will actually be called, you can use the OVERLAY directive to inform the compiler of the actual call tree. In this case, the compiler will overlay locals and parameters for the indirect call exactly as it would for a normal function call. Maintaining the overlay tree manually may be difficult and error prone. You might prefer the run-time expense of declaring all routines to be called through a pointer reentrant In this case, locals and parameters will be allocated on a stack -- not necessarily the 8051 stack pointed to by SP, but a stack maintained by software. See the manual and STARTUP.A51. In certain limited circumstances, the compiler is able to deduce the correct call tree even in the presence of function pointers. There's an app note on the topic. Typically this will be a constant table of functions, say event handlers for a state machine, all in the same linker segment as the caller. The linker sees a reference from the table to all the functions, and from the caller to the table, so it can build a call tree without help from the programmer. Separate compilation, where the called function isn't known to another module, usually requires manual intervention with the OVERLAY directive (or using the run-time stack with reentrant, or a coding technique that creates a static call chain, such as the dispatch function mentioned earlier).
Hi, Thanks for ur suggestions... If we wnat to use OVERLAY directive, we have to select OVERLAY (sfname ! *)in BL51 or NOOVERLAY in Misc controls. Is there any other way to define in .C file itself like #pragma... Thanks in advance