954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Basic C Question

Hi,

I have a basic doubt about C compiler option.
I have 10 functions in my environment and I want a particular function to go into a new section which will be defined in a file where the function is defined.

My question is:
Can we define a seperate section in C file for a particular function?

Please let me know if anyone knows.

Thanks,
SSK.

saravana_ssk
Newbie Poster
2 posts since Sep 2006
Reputation Points: 14
Solved Threads: 0
 

Not certain about your question -- can a function declared in one file call a function in another file? Yes, the program has two or more files they all must be linked together into one executable program. How to do that depends on the compiler you are using because every compiler is a little different.

What compiler and operating system?

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Thanks for your reply.

I am working on Metrowerks C compiler and the OS is solaris5.8 and linux24.

Actually, there was a typo error in my question. Sorry for that. :-)

Let's assume that I have 10 function in a c file called one.c.
I want function called void ten (void); to go into c particular memory range.

Can I control this by putting some kind of attibute or pragma to define a section for that particular function (ten)?

Hope this time the question is clear. :-)

Thanks,
Saravana.

saravana_ssk
Newbie Poster
2 posts since Sep 2006
Reputation Points: 14
Solved Threads: 0
 
Hi, I have a basic doubt about C compiler option. I have 10 functions in my environment and I want a particular function to go into a new section which will be defined in a file where the function is defined. My question is: Can we define a seperate section in C file for a particular function? Please let me know if anyone knows. Thanks, SSK.


Hm you need to performulate th question. Whats section? This word is too abstract
EDIT: Sorry after the second post its clearer

andor
Posting Whiz in Training
276 posts since Jun 2005
Reputation Points: 251
Solved Threads: 29
 

>>Can I control this by putting some kind of attibute or pragma to define a section for that particular function (ten)?

I never heard if a section, there is no such thing in standard C language.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

I think maybe you are looking for function pointers which can decide which function to execute dynamically depending on the type of input by the user or triggered by some condition in the program. So if you have ten functions in a file "functions.c" with the same signatures and return types and you want to call one of those functions depeding on the input of the user, you can declare a function pointer which can moulded into any function call on the fly.

More info can be found here:
http://theory.uwinnipeg.ca/programming/node86.html
http://www.newty.de/fpt/fpt.html
http://www.eskimo.com/~scs/cclass/int/sx10a.html
http://publications.gbdirect.co.uk/c_book/chapter5/function_pointers.html

Hope it helped, bye.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

> I want function called void ten (void); to go into c particular memory range.
You can, but why would you want to?

Both your operating systems are perfectly capable of running the code at the default address the linker gives to the function. If you move it too far, it might be outside of the address space the OS gives to user programs.

The question is very heavily dependent on the capabilities of your linker. I know "in principle" how to do this with the GNU linker, but only by studying the manual at length.

Manually locating bits of code is something I've only ever had to do for embedded systems where some code has to be placed in FLASH memory for example, and other code is loaded and run from RAM.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You