-
Using #pragma section funcname
None of the suggestions I have received regarding getting a function size
by subtracting function pointers has been satisfactory for my 'C' compiler.
I need the size of a function in order to copy it from ROM to RAM with memcpy().
We used this in assembler as below and had no problem.
.section Psectname,code,align=2
.export _FuncName
.export _FuncSize
_FuncSize .data.w (sizeof Psectname)
_FuncName:
Is there a way to get the size with a similar preprocessor in 'C'?
#pragma section sectname
WORD funcsize = sizeof(sectname);
void funcname(void){}
When I use the above, the compiler gives me the following error.
UNDECLARED NAME: "sectname"
-
Re: Using #pragma section funcname
Curtis,
There's no standard way to do what you're looking for in C. A function
is not an lvalue nor is an object in the sense of a memory chunk to
which you can write. Besides, different platforms implement functions in
very different ways: how would you measure the size of a dynamically
loaded function? and what about a swapped out function? Shared
libraries? BIOS code? I think the best way to handle this is by using
assembly code but remember that it's highly machine dependent. The
technique of casting function pointers to char * and then subtracting
one from another seems to work on my machine but I can't endorse the
results.
Danny
Curtis wrote:
>
> None of the suggestions I have received regarding getting a function size
> by subtracting function pointers has been satisfactory for my 'C' compiler.
> I need the size of a function in order to copy it from ROM to RAM with memcpy().
>
> We used this in assembler as below and had no problem.
>
> .section Psectname,code,align=2
> .export _FuncName
> .export _FuncSize
>
> _FuncSize .data.w (sizeof Psectname)
> _FuncName:
>
> Is there a way to get the size with a similar preprocessor in 'C'?
>
> #pragma section sectname
> WORD funcsize = sizeof(sectname);
> void funcname(void){}
>
> When I use the above, the compiler gives me the following error.
>
> UNDECLARED NAME: "sectname"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks