Source code se running program tak
Editing, translation, linking, loading aur execution ko alag samjhein; diagnostic kis stage se aa sakta hai, pehchanein.
Is chapter mein10 sections
Source file programmer ka likha hua text hai. Running program ko computer execute karta hai. Yeh chapter dono ke beech ke steps samjhata hai aur batata hai ki program chalane ke liye valid C likhne ke alawa kya chahiye.
1. Source text se shuru karein
Editor mein source text likhkar commonly .c ending wali file mein save karte hain. Saving text store karti hai. Building tools se program translate aur connect karwati hai. Running environment se result execute karwati hai. Yeh teen alag actions hain.
#include <stdio.h>
int main(void) {
puts("Ready.");
return 0;
}Yeh complete hosted C17 program hai. Header translation ke liye information deta hai. Hosted startup main ko call karta hai, aur puts text output request karta hai. Output successful ho toh Ready. aur newline likhe jaate hain. Source likhne se call khud perform nahi hoti.
2. Common pipeline useful model hai
- Preprocess
- Translate
- Link
- Load aur run
Compiler driver ek command ke peeche multiple stages arrange kar sakta hai. Suitably configured Unix-like toolchain par cc -std=c17 demo.c -o demo C17 build request kar sakta hai. Actual compiler names, commands aur executable formats vary karte hain. Yeh roles ka illustration hai, installation recipe ya har computer par same command ki guarantee nahi.
C standard conceptual translation phases define karta hai. Implementation specified behavior preserve karke work combine kar sakti hai. Har build ke liye disk par preprocessed file, assembly file ya separately visible object file chhodna required nahi. Distinctions samjhein, diagram ko universal physical process na banayein.
3. Preprocessing translation unit prepare karti hai
Preprocessing #include, macro replacement aur conditional inclusion handle karti hai. #include <stdio.h> header ki information available karta hai. Yeh kuch print nahi karta aur poori compiled library paste nahi karta. Har implementation mein header ka physical file hona bhi required nahi.
Preprocessing aur inclusion ke baad translate hone wala source translation unit banta hai. Bade program mein kai translation units ho sakte hain. Har unit separately translate ho sakta hai; shared declarations parts ka connection batati hain. Aage dekhenge ki declarations ka agree karna kyun zaroori hai.
4. Translation program ko check aur transform karti hai
Tools grammar, declarations, types aur doosre language requirements check karte hain. Woh optimise karke machine code aur related information bana sakte hain. Conventional object file later linking ke liye translated material store karti hai. Filename ka “object” C model ke integer variable jaise object se alag use hai.
Optimization unneeded calculations remove, calls inline ya different instructions choose kar sakti hai. Valid program ka required behavior respect karna hota hai. Undefined behavior wale program ko rescue karne ki promise nahi. Warning investigate karne ka useful evidence hai, lekin “no warnings” correctness ka proof nahi.
5. Linking separately prepared parts ko jodti hai
Declaration function describe kar sakti hai bina us source file mein body diye. Linking uses ko required definitions se jodti hai. Definition missing ho toh ek file ki successful translation ke baad bhi build fail ho sakta hai. Matching declarations program ki responsibility hain; linker complete C type checker nahi.
Static aur dynamic linking kuch program components connect karne ke alag tareeqe hain. Statically linked executable mein poora OS ya future ki har used file hona zaroori nahi. Dynamic linking mein link time, load time aur kabhi later runtime resolution ka work ho sakta hai. “Sab running se pehle” versus “sab sirf running ke dauran” wala simple split misleading hai.
6. Loading aur execution baad ke events hain
Ordinary hosted system execution context prepare, needed code aur data available karta hai aur startup se main call hota hai. Exact loader, runtime aur process mechanisms system-specific hain. Embedded freestanding C ka startup alag ho sakta hai. Successfully built executable bhi runtime resource unavailable hone par fail ho sakta hai.
| Problem | Kahan investigate karein |
|---|---|
| Malformed declaration | Source aur translation diagnostics |
| Function definition unavailable | Declarations, definitions aur build/link inputs |
| File open nahi hoti | Runtime environment, permissions aur error handling |
| Valid syntax ke saath galat bill | Specification, arithmetic aur program logic |
Header include karne se function declaration visible hui. Kya isse final program ke liye appropriate implementation available hona prove hota hai?
Explanation padhein
Nahi. Declaration interface information deti hai. Required definition ya implementation build aur execution environment se ab bhi provide honi chahiye. Isliye translation aur linking alag sawaal hain.
Primary references aur aage ki reading
- WG14 N1570 — public C11 committee draft: Sections 5.1.1.1–5.1.1.3, 5.1.2.2, and 7.1.2 is C17-baseline explanation ke core rules deti hain. Yeh public draft hai, final ISO publication nahi.
Optional visual model: Source se program tak follow karein
Source se program tak follow karein
VISUAL MODEL
Headers, macro replacement, translation units aur external definitions ko jodein. Ek definition chhodkar bhi dekhein.
Labelled excerpts config.h, main.c aur scale.c ke hain. Definition choice batati hai build mein scale.c diya gaya ya nahi.
/* config.h */ #define FACTOR 2int scale(int);/* main.c */ #include "config.h"int main(void) { return scale(3); }/* scale.c */ #include "config.h"int scale(int n) { return n * FACTOR; }
source—Current stagepreprocess—Baad ka stagecompile—Baad ka stagelink—Baad ka stageprogram—Baad ka stageconfig.h, scale declare aur FACTOR ko 2 define karta hai. main.c, scale call karta hai; build mein diya ho to scale.c definition deta hai.
Yeh translation phases ki conceptual grouping hai. Alag .o files aur compiler/linker executables common toolchain choices hain; C in artifacts ko require nahi karta. In chhoti files ko standard library function nahi chahiye.
Poora trace padhein
- config.h, scale declare aur FACTOR ko 2 define karta hai. main.c, scale call karta hai; build mein diya ho to scale.c definition deta hai.
- Har source file separately preprocess hoti hai. Header declarations deta hai aur scale.c ke FACTOR tokens, 2 ban jaate hain.
- Resulting translation units analyze aur translate hoti hain. Declaration ke saath main.c translate ho sakta hai; scale ki body main.c mein rakhna zaroori nahi.
- External call doosri translation unit ki scale definition se connect hoti hai.
- Linked program run ho sakta hai. scale(3), 6 compute karta hai aur main wahi value return karta hai.
Aage badhne se pehle
- Source save karna, program build karna aur run karna alag actions hain.
- Headers translation information dete hain; required definitions phir bhi supply karni hoti hain.
- Executable successful build ke baad runtime resource missing hone se fail ho sakta hai.
In ideas ko alag rakhein
- Declaration / Linked implementation
- Visible declaration interface describe karti hai; required implementation available hai, yeh prove nahi karti.
Translate hone ke baad missing function definition se fail hone wale program ko kaise explain karenge?
Optional: bolkar samjhein ya note rakhein. Tayyar hon toh aage badh sakte hain.Apni understanding check karein
Optional hai. Answers save ya send nahi hote; chapter kabhi lock nahi hota.
Har choice ki explanation padhein
- Complete executable body.
Declaration interface describe karti hai; body definition hoti hai.
- Linking successful hone ki guarantee.
Build ko program ki required definitions phir bhi chahiye.
- Function ke uses check karne ki information.
✓ Sahi reasoning. Suitable declaration calls check karne mein help karti hai, par missing body nahi deti.
C17
Pehle edition ka quick reference
Yeh compact reference existing links aur saved passages ke liye retained hai. Full context ke liye upar ki expanded lesson padhein.
Ek conventional toolchain C source ko neeche diye stages se executable mein badalti hai. Yeh common implementation pipeline hai; standard translation phases define karta hai, chaar separate tools ya intermediate files ki requirement nahi rakhta.
-
Preprocessing: Early source transformations har comment ko ek space se replace karti hain. Uske baad preprocessing
#include,#defineaur conditional compilation handle karti hai. Headers include aur macros expand hote hain, jisse aage translate karne ke liye preprocessed translation unit milti hai. -
Compilation: Compiler preprocessed source code ko assembly language ya intermediate code mein translate karta hai, saath hi syntax aur semantic analysis, type checking, aur code optimization bhi perform karta hai.
-
Assembly: Assembler assembly code ko machine code mein convert karta hai, jisse object files banti hain.
-
Linking: Conventional linker object files aur needed library components connect karke toolchain ke according references handle karta hai. Static linking selected object aur library code ko executable mein incorporate karti hai; har possible system component nahi. Dynamic linking mein link-time, load-time aur later runtime binding involved ho sakti hai, sirf ek universal resolution stage nahi.
Yeh multi-stage process modular development, code reuse, aur efficient program execution ko enable karta hai.
Agla idea padhne ke liye tayyar?
Mark this chapter as read whenever you feel ready.