473,396 Members | 1,725 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

scanf address

hi all
can anybody please tell me that how a C compiler searches for the
defintion of the standard functions like scanf,printf,etc?

Does the compiler knows in advance the location in memory where the
definitions of these functions lie?If not,then what does it do to find
the defintions fo these functions?

Also can you please tell me that what is the difference between an
object file and an executable file.

Thanks in advance,

Aditya
Nov 14 '05 #1
3 2314
ad************@gmail.com (aditya) writes:
can anybody please tell me that how a C compiler searches for the
defintion of the standard functions like scanf,printf,etc?

Does the compiler knows in advance the location in memory where the
definitions of these functions lie?If not,then what does it do to find
the defintions fo these functions?

Also can you please tell me that what is the difference between an
object file and an executable file.


All of these questions are system-specific. You should ask them
in a newsgroup that talks about whatever system you're interested
in.
--
"I'm not here to convince idiots not to be stupid.
They won't listen anyway."
--Dann Corbit
Nov 14 '05 #2

"aditya" <ad************@gmail.com> wrote

can anybody please tell me that how a C compiler searches for the
defintion of the standard functions like scanf,printf,etc?
Compilers vary. Normally the standard library is part of a library file,
which contains labels (like "scanf" or "printf") which the linker can use to
match the call in the source to the executable in the library. The
executable code is then extracted from the library, maybe modified so that
it runs from the right address, and added into the user's program.
However a modern system tends to be a lot more complicated, since function
calls may be resolved at runtime, for instance printf() may call one
function when invoked from a console, and another if the program is opened
by clicking on an icon.
Does the compiler knows in advance the location in memory where the
definitions of these functions lie?If not,then what does it do to find
the defintions fo these functions?
No, the compiler knows where they are in the library file, because the
library file contains a list of all the functions inside. When it gets a
name, it checks against the library list, and if there is a match, extracts
the function.
Also can you please tell me that what is the difference between an
object file and an executable file.

An object file is an intermediate file (not all compilers create them). It
is very similar to a library file, in that it contains largely-compiled
code, and a list of function names for linking. Sometimes the code will need
slight modificaton before including in the user's executable.
An executable file is a machine-code file. Normally all the labels and other
C-specific information will be stripped away, and it might not even be
possible to tell that the code has been compiled from C. Functions are
linked by jumps to raw addresses.
Nov 14 '05 #3
aditya wrote:
hi all
can anybody please tell me that how a C compiler searches for the
defintion of the standard functions like scanf,printf,etc?

Does the compiler knows in advance the location in memory where the
definitions of these functions lie?If not,then what does it do to find
the defintions fo these functions?

Also can you please tell me that what is the difference between an
object file and an executable file.

Thanks in advance,

Aditya


The compiler generates code. The code contains a call instruction to the
scanf function, and a record for the linker telling it that this is an
unresolved reference. That is all.

The linker sees this instructions in the object file generated by the
compiler, and searches for the function in its libraries list. When it
founds it, it inserts the machine code of the scanf function into the
growing executable.

The linker doesn't know where the code will be actually in memory when
is loaded. It just generates an executable file on the disk, that is
later loaded into RAM when the program is prepared for execution.

The loader reads the executable from disk, assigns a memory space for
it, and copies the file from disk into RAM, adjusting some parts of it
inserting where needed the adresses relative to the load address.
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Steve Zimmerman | last post by:
This post is not intended as an argument to any other post, just some simple scanf experiments that I wanted to share. I found experiments 5 and 6 the most educational. Also, I thought...
13
by: Kris | last post by:
Hi! I have the following instruction: char wyp; scanf("%c",&wyp); this scanf is in a while loop, and I want it to get EXACTLY one character each time. Does anyone knows how to do it? BTW....
39
by: Teh Charleh | last post by:
OK I have 2 similar programmes, why does the first one work and the second does not? Basically the problem is that the program seems to ignore the gets call if it comes after a scanf call. Please...
12
by: B Thomas | last post by:
Hi, I was reading O'Reilly's "Practical C programming" book and it warns against the use of scanf, suggesting to avoid using it completely . Instead it recomends to use using fgets and sscanf....
14
by: Peter Mount | last post by:
Hello I'm having trouble with " scanf("%c", &answer);" on line 20 below. When I run the program in cygwin on Windows 98SE it skips that line completely and ends the program. Does scanf have...
4
by: sushant | last post by:
hi why do we use '&' operator in scanf like scanf("%d", &x); but why not in printf() like printf("%d" , x); thnx in advance sushant
30
by: James Daughtry | last post by:
char array; scanf("%19s", &array); I know this is wrong because it's a type mismatch, where scanf expects a pointer to char and gets a pointer to an array of 20 char. I know that question 6.12...
62
by: Argento | last post by:
I was curious at the start about how ungetc() returns the character to the stream, so i did the following coding. Things work as expected except if I change the scanf("%c",&j) to scanf("%d",&j). I...
9
by: Cao Yi | last post by:
Hi, here's a fract of codes, and what's the line "scanf("%lf%*", &cvi)" doing? ============================= do { printf("\nCoefficient: "); scanf("%lf%*", &cvi); getchar(); } while (cvi <=...
0
by: vlsidesign | last post by:
I am a newbie to C, and was hoping to get a little bit better handle on this until I get deeper into pointers, etc. I kind of understand it some, but still unfamiliar because I haven't got to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.