Basic C Question

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2006
Posts: 2
Reputation: saravana_ssk is an unknown quantity at this point 
Solved Threads: 0
saravana_ssk saravana_ssk is offline Offline
Newbie Poster

Basic C Question

 
0
  #1
Sep 21st, 2006
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.
Last edited by saravana_ssk; Sep 21st, 2006 at 11:18 am. Reason: Typo error
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,609
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1491
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Basic C Question

 
0
  #2
Sep 21st, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 2
Reputation: saravana_ssk is an unknown quantity at this point 
Solved Threads: 0
saravana_ssk saravana_ssk is offline Offline
Newbie Poster

Re: Basic C Question

 
1
  #3
Sep 21st, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 275
Reputation: andor has a spectacular aura about andor has a spectacular aura about andor has a spectacular aura about 
Solved Threads: 29
andor's Avatar
andor andor is offline Offline
Posting Whiz in Training

Re: Basic C Question

 
1
  #4
Sep 21st, 2006
Originally Posted by saravana_ssk View Post
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
Last edited by andor; Sep 21st, 2006 at 11:34 am.
If you want to win, you must not loose (Alan Ford)
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,609
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1491
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Basic C Question

 
0
  #5
Sep 21st, 2006
>>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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,648
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 473
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Basic C Question

 
0
  #6
Sep 21st, 2006
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..._pointers.html

Hope it helped, bye.
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Basic C Question

 
1
  #7
Sep 21st, 2006
> 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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC