C (chiyowoyero cha mapulogalamu)
C (yakuzunulika kuti /ˈsiː/ – nga ni chilembo c)[1] ni chiyowoyero cha mapulogalamu ya chilato chambula kukazikika. Likapangika mu 1970s na Dennis Ritchie ndipo yikulutilira kugwiliskirika nchito comene ndiposo kukhaska ŵanthu ŵanandi. Mu ka kwatiro, kaŵiro ka C kakulongora makora nkhongono za ma CPU. Likusanga nchito yakukhalilira mu vilemba vya udesi vya Ndondomeko Zilala (chomene-mene me ma kenele[2]), sigilo za makina, na ndondomeko zidikanyi, kweni kugwiliskira ntchito kwake mu mapulogalamu gha chilato chikhazikiki kakukhila.[3] C yikugwiriskirika nchito comene mu kazengekero ka makompyuta ivyo vikufuma ku ma makompyuta gha utana ghakuru nkhanira mpaka ma microcontrollers na embedded systems ghachoko chomene-mene.
Nga chiyowoyelo cha ma pulogramu icho chikalondezgapo pa chiyowoyelo cha ma pulogramu cha B, C wakapangika pakwamba ku Bell Labs na Ritchie pakati pa 1972 na 1973 kuti ŵazenge vyakugwiriskira nchito ivyo vikugwira ntchito pa Unix. Likagwiriskirika nchito pa Kukhazikiskaso kenele ya Ndondomeko Yilala Ya Unix.[4] Mu vilimika vya m’ma 1980, C wakamba kutchuka pachokopachoko. Icho chazgoka chimoza mwa viyowoyero ivyo vikugwiriskirika nchito chomene pakupanga mapulogiramu,[5][6] na msutuli wa C ukusangika pafupifupi pa mazengero gha makompyuta ghose gha mazuŵa ghano na Ndondomeko Zilala Zose. Buku la The C Programming Language (Chiyowoyero cha C), ilo likalembeka pamoza na uyo wakalemba chiyowoyero cha C pakwambilila penecho, yikateŵetera kwa vilimika vinandi nga ni muyezo wa ciyowoyero cha C chakufikapo.[7][8] C yaŵikika pa mlingo kufuma mu 1989 na wupu wa American National Standards Institute (ANSI) na, mwakulondezgapo, mwakukolelana na ŵa International Organization for Standardization (ISO) na ŵa International Electrotechnical Commission (IEC).
C ni chiyowoyero cha Kulangula mwandondomeko, yakuzomela kulemba ma pulogalamu ghakundandikwa, lexical variable scope, na Kawerezgawerezga, pamoza na kalembero kambula kusintha (ka ma pulogalamu). yikakwatika kuti yi sutulikenge kuti yipe chizomelezgo cha pafupi na pasi cha kukhwaska memore na mazengero gha viyowoyero ghakukolelana makola yene kwa malangulo gha makina, vyose ivi na ufighiliro wa runtime wakukhira. Nangauli na nkhongono zake zapasi, chiyowoyero ichi chikapangika kuti chikhozgere mapulogiramu ghakupambanapambana. Pulogalamu ya C ya Kulondezga miyezgo yakulembeka na chirato cha upusu wa kunyamulika yingasutulilika kuti yende pa ma pulatifomu ghakupambanapambana gha ma kompyuta na Ndondomeko Zilala nakusintha kudoko waka kwa malembero gha udesi ghakhe.
Kwamba 2000, C nyengo zose yaŵa pakati pa viyowoyero vinayi vyapachanya na TIOBE index, icho ntchipimo cha kutchuka kwa viyowoyero vyakupanga mapulogalamu.[9]
Kuwoneseska mwakudumura
[lemba | kulemba source]C ni chiyowoyero cha kulangura, cha ndondomeko mu udawuko wa ALGOL. yili na kalembero kambula kusintha. mu C, vilembero videsi vyakuthyeka vyose vikujalilika mu ma subroutines (yakuchemekaso ma "function", kweni mu ka ng'anamuliro ka functional programming chara). Function parameters ghakupizgika kwendela value, nangawuri ma arrays ghakupizgika nga ma pointer, ndiko kuti keyala ya chinthu cha kwamba mu array iyo. Pass-by-reference yikutetezgeleka mu C pakupizga nkhanira-nkhanira ma pointer kwa chinthu icho chikupangika reference.
Program source text ya C ni vilembo vya udesi vya free-form. Ma Semicolons ghakutheleska ma statements, apo ma curly braces ghakugwiliskika kugawa ma statements mu ma blocks.
Chiyowoyelo cha C chikulongolaso vimanyisko ivi:
- Chiyowoyero ichi chili na nambara yichoko, yakukhazikika ya mazgu ghakuzirwa, kusazgapo gulu lose la ma control flow gha primitive:
if/else
(panji nthe/pala apo cha),for
(ya),do/while
(chita nthe/pala),while
(apo), naswitch
(sinthiska). Mazina ghakusoleka na wolemba yakupambaniskika yayi na mazgu ghakuzirwa gha C na mtundu uliwose wa sigil. - Lili na nambala yikuru ya luso-lakupenda, bitwise, na ma operator gha logic
- Ma assignment yakujumpha yimoza yangachitika mu statement ghamoza.
- ma Function:
- Value ya Function yinga yingazelezgeka, para yikukhumbikwa yayi.
- Function na pointer ya yikuzomela run-time polymorphism ya ad hoc.
- Functions vingalongosoreka yayi mu scope ya lexical ya ma functions yanyakhe.
- Ma Variable lingalongosoreka mukati mwa Function, pamoza na scope.
- Function yingajichema yekha, ntheura recursion yikufighililika.
- Kulemba Data kuli kwa static, kweni yikuchichizgika mwakufowoka; data yose yili na type, kweni ma implicit conversions ghangaŵapo.
- Ma types yakulongosoreka na mwene (typedef) na ya kusazga yanandi-yanandi yangachitika.
- Mitundu ya data yakusazgikira yakupambanapambana (struct) yikuzomerezga kuti vinthu vyakukhwaskana na data visangike na kugaŵika nga ni chigaŵa. Ivyo vili mu structs yose vingayaniskika yayi na kugwiliskira nchito opareshoni yimoza yakupangika (vinthu vikwenera kuyaniskika paŵekha).
- Union ni chizengero icho chili na viŵaro vyakukhwaskana; likuzomerezga mitundu yinandi ya data kuti yigaŵane malo ghamoza ghakukumbukira.
- ma Array Enumerated types nga machitiko kwendela lizgo lakuzirwa la
enum
. Iwo ŵakusinthika mwawanangwa na manambara gha integer. - ma Enumerated types nga machitiko kwendela lizgo lakuzirwa la
enum
. Iwo ŵakusinthika mwawanangwa na manambara gha integer. - ma Strings ni ma data type payekha yayi, kweni yakukhazikiskika nga null-terminated character arrays.
- Kufika pa mlingo wapasi wa memory ya kompyuta nkhwamacitiko mwa kusintha maadiresi gha makina kuŵa ma pointer.
- ma Procedures (ma subroutines agho ghakuwezga cha ma value) ni nkhani yapadera ya Fuction, na return type yambula kanthu ya
void
. - Memore yingapika kwa pulogalamu kwendela ma calls kwa ma library routines.
- Preprocessor yikulongosora vinthu vikuruvikuru, kuŵikamo fayilo ya source code, na kuŵika vinthu pamoza.
- Pali mtundu wakwamba wa modularity: mafayilo ghangapangika padera na kukolerana pamoza, na kulaŵilira ivyo vikuchitika na vinthu vya data ivyo vikuwoneka ku mafayilo ghanyake kwizira mu mikhaliro yakukhazikika na yakunja.
- Ntchito zakusuzga nga ni I/O, kugwiliskira ntchito vingwe, na masamu vikupelekeka nyengo zose ku ndondomeko za layibulare.
- Khodi ilo likupangika pamanyuma pa kuwunganya lili na vyakukhumbikwa vyambura kusuzga pa pulatifomu iyo yili pasi, ivyo vikupangiska kuti liŵe lakukwana pakupanga ndondomeko zakugwiliskira ntchito na kugwiliskira ntchito mu ndondomeko zakuŵikika.
Nangauli C yikusazgapo yayi vinthu vinyake ivyo vikusangika mu viyowoyero vinyake. (nthe object orientation na garbage collection), ivi vingakwaniskika panji kuyezgeleka, kanandi kwizira mu kugwiliskira nchito malaibulale gha kuwaro (nthe GLib Object System panjiso Boehm garbage collector).
Ubale na viyowoyero vinyake
[lemba | kulemba source]Viyowoyero vinandi vya pamanyuma vikabwereka mwaluŵiro panji mwambura kumanyikwa kufuma ku C, nthe C++, C#, C shell ya Unix, D, Go, Java, JavaScript (kusazgapo transpilers), Julia, Limbo, LPC, Objective-C, Perl, PHP, Python, Ruby, Rust, Swift, Verilog na SystemVerilog (viyowoyero vyakulongosora vya hardware).[10] Viyowoyero ivi vyakopa vinandi mwa ma control structures yawo na vinyake mwa vyakuzirwa kufuma ku C. Ŵanandi ŵa iwo ŵakuwoneskaso kuti ŵakuyana chomene malango gha kalembero na C, ndipo ŵakutemwa kuphatikizapo mazgu ghakumanyikwa na mazgu gha C na ndondomeko za mtundu wakubisika, viyerezgero vya data, na semantics ivyo vingaŵa vyakupambana comene.
Mbiri
[lemba | kulemba source]Kukwatika kwakwamba
[lemba | kulemba source]Year | Informal name |
Official standard |
---|---|---|
1972 | first release | — |
1978 | K&R C | — |
1989, 1990 |
ANSI C, C89, ISO C, C90 |
ANSI X3.159-1989 ISO/IEC 9899:1990 |
1999 | C99, C9X | ISO/IEC 9899:1999 |
2011 | C11, C1X | ISO/IEC 9899:2011 |
2018 | C17, C18 | ISO/IEC 9899:2018 |
2024 | C23, C2X | ISO/IEC 9899:2024 |
Future | C2Y | — |
Chiyambi cha C chikukolerana chomene na kupanga ndondomeko yakugwira ntchito Ndondomeko yilala ya Unix, iyo yikakhazikiska pakwamba mu chiyowoyero cha assembly pa PDP-7 na Dennis Ritchie na Ken Thompson, kusazgapo maghanoghano ghanandi kufuma ku ŵanyawo. Paumaliro, ŵakaghanaghana kuti ŵaŵike pulogiramu iyi ku PDP-11. Mtundu wakwamba wa PDP-11 wa Unix ukapangikaso mu chiyowoyero cha assembly.[4]
B
[lemba | kulemba source]Thompson wakakhumbanga chiyowoyero cha pulogiramu yakupangira vinthu vyakugwiriskira ntchito pa pulatifomu yiphya. Wakayezga dankha kulemba Fortran compiler, kweni mwaluŵiro wakaleka fundo iyi ndipo m’malo mwake wakapanga mtundu wakudumulika wa systems programming language yakuchekeka BCPL. ulongosora kwakuzomerezgeka kwa BCPL kukaŵako yayi pa nyengo iyo,[11] andipo Thompson wakasintha mazgu ghake kuti ghaŵe ghambura ‘mazgu ghanandi’ ndiposo ghakuyana waka na ALGOL yakupepuka iyo yikumanyikwa kuti SMALGOL.[12] Wakachema chakufumapo B,[4] kuchilongosora kuti "BCPL semantics na mazgu ghanandi gha SMALGOL".[12] Nge BCPL, B yikakaŵa na bootstrapping kuti viŵe vyambura kusuzga kutumizga ku makina ghaphya.[12] Paumaliro, vipangizo vichoko waka vikalembeka mu B chifukwa vikaŵa vyakuchedwa chomene ndipo vikatondeka kusanga mwaŵi wa vinthu vya PDP-11 nga ni addressability ya byte.
B yiphya na C yakwamba
[lemba | kulemba source]Mu 1971 Ritchie wakamba kusintha B, kuti wagwiriskirenge nchito vinthu vya PDP-11 yankhongono comene. Kuwonjezerapo kwakuzirwa kukaŵa mtundu wa data ya malembo. Wakacema ici kuti B Muphya (NB).[12] Thompson wakamba kugwiliskira ntchito NB pakulemba kernel ya Unix kernel, ndipo ivyo wakakhumbanga vikapangiska kuti chiyowoyero chiŵe chiwemi.[12][13] Kufika mu 1972, mitundu yakusambazga yikasazgikira ku chiyowoyero cha NB: NB yikaŵa na magulu gha int
na char
. Pointers, luso la kupanga pointers ku mitundu yinyake, ma arrays gha mitundu yose, na mitundu iyo yikwenera kuwelera kufuma ku milimo vyose vikasazgikirapo. Ma arrays mukati mwa mazgu ghakazgoka vimanyikwiro. Ŵakalemba buku liphya lakuwunganya vinthu, ndipo chiyowoyero ichi chikasintha zina kuŵa C.[4]
C compiler na vinyake ivyo vikapangika nayo vikasazgikika mu Version 2 Unix, uwo ukumanyikwaso kuti Research Unix.[14]
Kulembaso ma Zengero na kenero ya Unix
[lemba | kulemba source]Pa Version 4 Unix, iyo yikafumiskika mu Novembala 1973, Unix kernel yikaŵikikaso mu uphya mu C.[4] Pa nyengo iyi, chiyowoyero cha C chikaŵa kuti chasanga vinthu vinyake vyankhongono nga ni mitundu struct
.
Preprocessor yikayambiskika mu 1973 pakuchichizga na Alan Snyder ndiposo chifukwa cha kumanya kuti nthowa zakuŵikamo mafayilo izo zili mu BCPL na PL/I. Mtundu wake wakwamba uwo ukapelekeka ukaŵa waka na mafayilo na vinyake vyambura kusuzga vyakusintha: #include
na #define
. Pamanyuma pa nyengo yichoko waka, likasazgikirapo, chomenechomene na Mike Lesk ndipo pamanyuma na John Reiser, kuti ŵasazgireko macros na mphindano na kuwunganya kwakuzomerezgeka.[4]
Unix yikaŵa yimoza mwa ma kernel ghakwamba ghakugwiliskira ntchito mu chiyowoyero chinyake padera pa msonkhano . Vinthu ivyo vikachitika pakwamba vikusazgapo ndondomeko ya Multics (iyo yikalembeka mu PL/I ) na Pulogalamu Yakulongozga (MCP) ya Burroughs B5000 (iyo yikalembeka mu ALGOL ) mu 1961. Pafupifupi mu 1977, Ritchie na Stephen C. Johnson ŵakasinthaso vinthu vinyake kuti . chiyowoyero kuti chiwovwire kunyamulika kwa dongosolo la Unix. Johnson's Portable C Compiler ndiyo yikaŵa maziko ghakuŵika C pa mapulatifomu ghaphya.[13]
K&R C
[lemba | kulemba source]IMu 1978, Brian Kernighan na Dennis Ritchie ŵakasindikizga buku lakwamba la Chiyowoyero cha C . Buku ili likamanyikwa kuti K&R kufuma ku vimanyikwiro vyakwamba vya awo ŵakalemba, ndipo likateŵetera kwa vilimika vinandi nga ni chiyowoyero chambura kumanyikwa . Mtundu wa C uwo ukulongosora ukuchemeka kuti " K&R C ". Pakuti iyi yikafumiskika mu 1978, sono yikuchemekaso kuti C78 . Buku lachiŵiri la likulongosora vya ANSI C standard iyo yikapangika pamanyuma, iyo yikulongosoreka musi umu.
K&R yikayambiska viyowoyero vinandi:
- Standard I/O library
long int
mtundu wa dataunsigned int
mtundu wa data- Compound assignment operators of the form
=op
(such as=-
) were changed to the formop=
(that is,-=
) to remove the semantic ambiguity created by constructs such asi=-10
, which had been interpreted asi =- 10
(decrementi
by 10) instead of the possibly intendedi = -10
(leti
be −10).
Nangauli panyuma pakuti 1989 ANSI standard yalembeka, kwa vilimika vinandi K&R C yikaŵa kuti yichali kuwoneka kuti ni " lowest common denominator " iyo ŵakupanga mapulogiramu gha C ŵakajikanizganga para ŵakukhumba kunyamura chomene, chifukwa mabuku ghanandi ghakale ghakaŵa kuti ghachali kugwiliskirika ntchito, ndiposo chifukwa chakuti K&R yikalembeka makora . C khodi ingaŵa yakuzomerezgeka Standard C nayo.
Mu mitundu yakwamba ya C, milimo pera iyo yikuweleska mitundu yinyake padera pa iyo int
yikwenera kupharazgika usange yikugwiriskirika nchito pambere nchito yindalongosoreke; ntchito izo zikugwiriskirika nchito kwambura kupharazga dankha zikaŵa kuti zikuwelera mtundu int
.
Mwa chiyezgelelo:
long some_function(); /* This is a function declaration, so the compiler can know the name and return type of this function. */
/* int */ other_function(); /* Another function declaration. Because this is an early version of C, there is an implicit 'int' type here. A comment shows where the explicit 'int' type specifier would be required in later versions. */
/* int */ calling_function() /* This is a function definition, including the body of the code following in the { curly brackets }. Because no return type is specified, the function implicitly returns an 'int' in this early version of C. */
{
long test1;
register /* int */ test2; /* Again, note that 'int' is not required here. The 'int' type specifier */
/* in the comment would be required in later versions of C. */
/* The 'register' keyword indicates to the compiler that this variable should */
/* ideally be stored in a register as opposed to within the stack frame. */
test1 = some_function();
if (test1 > 1)
test2 = 0;
else
test2 = other_function();
return test2;
}
Mtundu int
wa vimanyikwiro ivyo vikuyowoyeka vingaŵa kuti vyalekeka mu K&R C, kweni vikukhumbikwa mu vigaŵa vyakulondezgapo.
Pakuti vipharazgo vya ntchito vya K&R vikaŵavya uthenga uliwose wakukhwaskana na mphindano za ntchito, kuwoneseska kwa mtundu wa parameter ya ntchito kukachitika yayi, nangauli ŵanyake awo ŵakulemba mabuku ŵangapeleka uthenga wakuchenjezga usange ntchito ya ku malo ghawo yikachemeka na nambara yakubudika ya mphindano, panji usange yikuchemeka mwakupambanapambana ku ntchito yakuwalo . ŵakagwiliskiranga ntchito manambara panji mitundu yakupambanapambana ya mphindano. Vipangizo vyapadera nga ni Unix's lint utility vikapangika ivyo (pakati pa vinyake) vingawona usange ntchito yikugwiriskirika nchito mwakuyana mu mafayilo ghanandi ghakufumapo.
Mu vyaka ivyo vikalondezgapo panyuma pa kupharazgika kwa K&R C, vinthu vinandi vikasazgikira ku chiyowoyero ichi, ivyo vikakhozgeka na ŵakuwunganya kufuma ku AT&T (makamaka PCC ) na ŵanyake awo ŵakaguliskanga. Vinthu ivi vikaŵa:
void
functions (i.e., function zambura value yakuwelera)- functions returning
struct
orunion
types (previously only a single pointer, integer or float could be returned) - assignment for
struct
data types - enumerated types (kale, vilongosolero vya preprocessor vya mtengo wakukhazikika wa integer vikagwiriskirika nchito, mwachiyelezgero
#define GREEN 3
)
Chiŵerengero chikuru cha kusazgirako na kusoŵa kwa mgwirizano pa layibulare yakumanyikwa , pamoza na kutchuka kwa chiyowoyero ndiposo kuti nanga mbakulemba Unix ŵakakwaniska yayi kukhazikiska makora mazgu gha K&R, vikapangiska kuti paŵe kukhumbikwa kwa kuŵika vinthu mwakuyana.[15]
ANSI C na ISO C
[lemba | kulemba source]Mu vilimika vya kumanyuma vya m’ma 1970 na 1980, mitundu ya C yikaŵikika pa ma computer ghakupambambana nthe mainframe computers, minicomputers, na microcomputers, kusazgapo IBM PC, apo ŵanthu ŵakamba kuyimanya chomene.
Mu 1983, ŵa American National Standards Institute (ANSI) ŵakapanga komiti, X3J11, kuti yiŵikepo ndondomeko yakumanyikwa ya C. X3J11 yikakhazikika pa ndondomeko ya C pa kukhazikiska kwa Unix; kweni chigaŵa cha layibulare ya Unix C icho chikunyamulika yayi chikapelekeka ku IEEE working group 1003 kuti chiŵe maziko gha 1988 POSIX standard. Mu 1989, muyezo wa C ukazomerezgeka nga ni ANSI X3.159-1989 "Chiyowoyero cha C". Mtundu uwu wa chiyowoyero ichi kanandi ukuchemeka kuti ANSI C , Standard C, panji nyengo zinyake C89.
Mu 1990, ANSI C standard (na kusintha kwa mawonekero) yikazomerezgeka na wupu wa pa charu chose (ISO) nga ni ISO / IEC 9899: 1990, iyo nyengo zinyake yikuchemeka C90. Ntheura, mazgu ghakuti "C89" na "C90" ghakung'anamura chiyowoyero chimoza cha pulogiramu.
ANSI, nga ni mabungwe ghanyake ghakukhwaskana na malango gha charu, ghakupangaso yayi malango gha C paŵekha, kweni ghakulondezga malango gha C gha pa charu chose, agho ghakusungika na gulu la ntchito ISO / IEC JTC1 / SC22 / WG14. Kuzomerezga kwa charu chose kwa kusintha kwa ndondomeko ya pa charu chose kanandi kukuchitika mu chaka chimoza kufuma apo ISO yikasindikizgikira.
Chimoza mwa vigaŵa vya ndondomeko ya C standardization chikaŵa chakuti ŵapange superset ya K&R C, kusazgapo vinthu vinandi ivyo vikayambiskika pamanyuma pake vyambura kumanyikwa. Komiti ya vipimo yikasazgaposo vinthu vinyake vinandi nga ni viyezgelero vya nchito (vyakubwereka kufuma ku C ++), void
vimanyikwiro, wovwiri wa vimanyikwiro vya pa caru cose na malo , na kukhozga preprocessor. Nangauli mazgu ghakulembeka gha parameter declarations ghakasazgikirapo kuti ghaŵe na mtundu uwo ukugwiriskirika ncito mu C ++, K&R interface yikalutilira kuzomerezgeka, kuti yikolerane na source code iyo yikaŵapo.
C89 yikukhozgeka na ŵakulemba C ŵasono, ndipo makhodi ghanandi gha mazuŵa ghano gha C ghakukhazikika pa iyo. Pulogalamu yiliyose iyo yikulembeka mu Standard C pera ndiposo kwambura kughanaghana kuti yikuthemba pa hardware yizamuchitika makora pa pulatifomu yiliyose iyo yili na C yakukolerana, mu mphaka ya vyakugwiriskira ntchito vyake. Kwambura kucenjera nthena, mapulogiramu ghangawunganya waka pa pulatifomu yinyake panji na munthu munyake uyo wakuwunganya, cifukwa ca, mwaciyelezgero, kugwiliskira nchito malaibulale ghambura kumanyikwa, nga ni malaibulale gha GUI , panji kuthemba pa mikhaliro ya munthu uyo wakuwunganya panji pa pulatifomu nga ni . nga ni kukula kwa mitundu ya data na byte endianness.
Mu ivi vingachitika vakuti khodi yikwenera kuŵikika pamoza na ŵakulemba awo ŵakulondezga malango panji ŵa K&R C, __STDC__
macro yingagwiliskirika nchito kuti yigaŵire khodi mu vigaŵa vya Standard na K&R kuti yileke kugwiliskirika nchito pa K&R C-based compiler ya vinthu ivyo vikusangika mu Standard pera . C.
Pamanyuma pa ndondomeko ya ANSI / ISO standardization, chiyowoyero cha C chikalutilira kuŵa chambura kusintha kwa vyaka vinandi. Mu 1995, kusintha kwa malango 1 ku 1990 C standard (ISO/IEC 9899/AMD1:1995, iyo yikumanyikwa mwambura kumanyikwa kuti C95) kukafumiskika, kuti ŵanozge vinyake na kusazgirako wovwiri ukuru ku vimanyikwiro vya pa caru cose.[16]
C99
[lemba | kulemba source]Muyezo wa C ukasinthikaso kuumaliro wa vilimika vya m'ma 1990, ndipo ukapangiska kuti ISO/IEC 9899:1999 yilembeke mu 1999, iyo yikuchemeka kuti " C99 ". Kufuma nyengo iyo, likasinthika katatu na Technical Corrigenda.
C99 wakayambiska vinthu vinandi viphya, kusazgapo milimo ya mu mzere , mitundu yinandi yiphya ya data (kusazgapo long long int
na complex
mtundu wakuyimira manambara ghakusuzga ), ma array gha utali wakusinthasintha na ŵabali ŵa ma array ghakusinthasintha , wovwiri wakukhozga wa IEEE 754 floating point, wovwiri wa variadic macros (macros of variable ). arity ), na kukhozgera vyakuyowoya vya mzere umoza ivyo vikwamba na //
, nga umo vikuŵira mu . BCPL panji C ++. Vinandi mwa vinthu ivi vikaŵa kuti vyaŵikika kale nga ni vyakuwonjezera mu ma C compilers ghanandi.
C99 ndiyo yikukolerana chomene na C90, kweni yikukhozga chomene mu nthowa zinyake; makamaka, chipharazgo icho chikusoŵa mtundu wakulongosora int
chilijeso mwachindunji. Macro yakumanyikwa __STDC_VERSION__
yikulongosoreka na mtengo 199901L
kuti yilongore kuti wovwiri wa C99 ulipo. GCC , Solaris Studio , na ŵanyake awo ŵakulemba C sono [ nyengo wuli? ] vikovwira vinandi panji vyose ivyo vili mu C99. C compiler mu Microsoft Visual C++ , nangauli, wakugwiriskira ncito muyezo wa C89 na vigaŵa vya C99 ivyo vikukhumbikwa kuti vikolerane na C++11 . [ vikukhumbikwira kusintha ]
Kusazgirapo apa, muyezo wa C99 ukukhumba wovwiri wa vimanyikwiro vyakugwiriskira ncito Unicode mu mtundu wa malembo ghakucimbira (mwaciyelezgero \u0040
panji \U0001f431
) ndipo ukuyowoya wovwiri wa mazina gha Unicode ghambura kupangika.
C11
[lemba | kulemba source]Ntchito yikamba mu 2007 pa kusintha kunyake kwa C standard, iyo yikuchemeka mwambura kumanyikwa kuti "C1X" m'paka apo yikasindikizgika mwakuzomerezgeka na ISO / IEC 9899:2011 pa Disembala 8, 2011. Komiti ya C standards yikazomerezga malango ghakuchepeska kuzomerezga vinthu viphya ivyo vikaŵa kuti vindachitike . ŵayezgeka na kukhazikiska uko kulipo.
C11 standard yikusazgapo vinthu vinandi viphya ku C na layibulare, kusazgapo mtundu wa generic macros, vigaŵa vyambura kumanyikwa, wovwiri wa Unicode wakunozga, ntchito za atomiki, kuŵika vingwe vinandi, na ntchito zakuwonera mphaka. Iwo ukupangiskaso kuti vigaŵa vinyake vya layibulare ya C99 iyo yilipo viŵe vyakusankha, ndipo vikupangiska kuti viŵe vyakukolerana na C ++. Macro yakumanyikwa __STDC_VERSION__
yikulongosoreka kuti 201112L
yikulongora kuti wovwiri wa C11 ulipo.
C17
[lemba | kulemba source]C17 ni zina lambura kumanyikwa la ISO / IEC 9899: 2018, ilo likumanyikwa na chiyowoyero cha C icho chikasindikizgika mu Juni 2018. Likulongosora yayi vinthu viphya vya chiyowoyero, likulongosora waka vyaukadaulo, na kulongosora ivyo vikubudika mu C11. Macro yakumanyikwa __STDC_VERSION__
yikulongosoreka kuti 201710L
yikulongora kuti wovwiri wa C17 ulipo.
C23
[lemba | kulemba source]C23 ni zina lambura kumanyikwa la chiyowoyero chikuru cha C chasono. Iwo ukamanyikwanga mwambura kumanyikwa kuti "C2X" kwizira mu kukura kwake kunandi. C23 yikasindikizgika mu Okutobala 2024 nga ni ISO / IEC 9899: 2024. Macro yakumanyikwa __STDC_VERSION__
yikulongosoreka kuti 202311L
yikulongora kuti wovwiri wa C23 ulipo.
C2Y
[lemba | kulemba source]C2Y ni zina lambura kumanyikwa la chiyowoyero chikuru cha C, pamanyuma pa C23 (C2X), icho chikugomezga kuti chizamufumiskika pamanyuma mu vyaka khumi vya 2020, ntheura '2' mu "C2Y". Mundandanda wakwamba wa C2Y ukafumiskika mu Febuluwale 2024 nga ni N3220 na gulu lakugwira ntchito la ISO / IEC JTC1 / SC22 / WG14.[17]
C ya Embedded
[lemba | kulemba source]Mu mbiri, mapulogalamu gha C ghakuŵikika ghakukhumba kusazgirako kwambura kumanyikwa ku chiyowoyero cha C kuti ghawovwire vinthu vyakuziziswa nga ni masamu ghakukhazikika , mabanki ghanandi ghakupambanapambana ghakukumbukira , na ntchito zakwamba za I / O.
Mu 2008, Komiti ya C Standards yikasindikizga lipoti la luso ilo likasazgirako chiyowoyero cha C kuti limazge nkhani izi mwa kupereka fundo yakuyana kuti vyose ivyo vikugwiriskirika nchito vilondezgekenge. Likusazgapo vinthu vinandi ivyo vikusangika mu C wakumanyikwa yayi, nga ni masamu ghakukhazikika, malo gha adiresi ghakuchemeka, na adiresi ya I/O hardware.
Syntax
[lemba | kulemba source]C yina dango la kalembero yakuzomeleka yakukhazikika na Muyezo wa C.[18] Kumalizga kwa mizere kanandi nkhwakuzirwa yayi mu C; kweni, mphaka ya mzere yili na ng’anamuro pa nyengo ya preprocessing. Makomenti ghangawoneka pakati pa ma delimiters /*
na */
, panjiso (kwamba C99) kulondezga //
m’paka kuumaliro wa mzere. makomenti ghakukhozgeka na /*
na */
ghaku ŵazgika yayi ndipo ndondomeko iyi ya ma characters yikung’anamulika yayi nga ma delimiters pala yasangika mukati mwa ma string panjiso ma character literal.[19]
Mafayilo gha C source ghali na vipharazgo na vilongosolero vya ntchito. Malongosolero gha ntchito, nayo, ghali na vipharazgo na mazgu . Vipharazgo vikulongosora mitundu yiphya mwakugwiliskira nchito mazgu ghakuzirwa nga ni struct
, union
, na enum
, panji kugaŵira mitundu ku ndipo panji kusunga malo ghakusungirako vyakusintha viphya, kanandi pakulemba mtundu uwo ukulondezgeka na zina la vyakusintha. Mazgu ghakuzirwa nga ni char
na int
kulongosora mitundu yakupangika. Vigaŵa vya khodi vikuŵikika mu vingwe ( {
ndipo }
, nyengo zinyake vikuchemeka "vingwe vyakukhota") kuti vichepeske kukura kwa vipharazgo na kugwira ntchito nga ni mazgu ghamoza gha vigaŵa vyakulongozga.
Pakuŵa chiyowoyero chakukhumbikwa chomene, C wakugwiliskira ntchito mazgu kuti walongosore ivyo munthu wangachita. Mazgu agho ghakumanyikwa comene ni mazgu ghakuyowoya , agho ghali na mazgu agho ghakwenera kuyezgeka, ndipo ghakulondezgapo pakuŵa semicolon; nga ni chigaŵa cha kuwunika, milimo yingachemeka ndipo vyakusintha vikugaŵirika mitengo yiphya. Kuti musinthe umo mazgu ghakuchitikira mwakulondezganako, C wakupeleka mazgu ghanandi ghakulongozga-kulongozga agho ghakumanyikwa na mazgu ghakuzirwa ghakusungika. Mapulogalamu ghakupangika ghakovwirika na if
... [ else
] kuchitika kwakuzomerezgeka ndiposo na do
... while
, while
, na for
kuchitika mwakuwerezgawerezga (kuzungulira). Mazgu agha for
ghali na mazgu ghakupambanapambana ghakwamba, kuyezga, na kuyambiskaso, ghanyake panji ghose ghangalekeka. break
ndipo continue
lingagwiriskikiya nchitu mukati mwa lupu. Break yikugwiriskirika nchito kuti yifumemo mu mazgu ghakujalira mkati ndipo kulutilira yikugwiriskirika nchito kuti yijumphe ku kuyambiskaso kwake. Paliso goto
mazgu ghambura kupangika agho ghakugaŵika mwaluŵiro ku chimanyikwiro chakusankhika mukati mwa ntchito. switch
wakusankha a case
kuti wakomeke mwakuyana na mtengo wa mazgu gha integer. Kupambana na viyowoyero vinyake vinandi, control-flow yizamuwira ku viyowoyero vinyake case
kupatulapo para yamara na a break
.
Mazgu ghangagwiliskira nchito mitundu yakupambanapambana ya vyakupangika ndipo ghangaŵa na mafoni ghakucemeka. Ndondomeko iyo mphindano za ntchito na operands ku ŵanandi awo ŵakugwira ntchito zikuwonekera zikumanyikwa yayi. Ma evaluation ghangaŵa kuti ghakunjilirapo. Kweni, vyose vyakukhwaskana na vyakuchitika (kusazgapo kusunga ku vyakusintha) vizamuchitika pambere " sequence point " yakulondezgapo yindakwane; fundo zakulondezgapo zikusazgapo umaliro wa mazgu ghakuyowoya ghaliyose, na kunjira na kuwelera kufuma ku foni ya ntchito yiliyose. Mfundo zakulondezganako zikuchitikaso pa nyengo ya kuwunika mazgu agho ghali na ŵanyake awo ŵakugwira ntchito ( &&
, ||
, ?:
na awo ŵakugwira ntchito na koma ). Ici cikuzomerezga kuti ŵantu awo ŵakupanga mapulogiramu gha C ŵaŵikepo mtima comene kuti ŵasange vyakucitika vyakugomezgeka kuluska umo vikukhumbikwira ku viyowoyero vinyake vyakupangira mapulogiramu.
Kernighan na Ritchie ŵakuti mu Mazgu ghakwamba gha Chiyowoyero cha C : "C, nga ni chiyowoyero chilichose, chili na viheni vyake. Ŵanyake awo ŵakugwira ntchito ŵali na fundo zambura kwenelera; vigaŵa vinyake vya mazgu vingaŵa viwemi." C standard yikayezga yayi kunozga vinandi vya viheni ivi, chifukwa cha umo kusintha kwanthena uku kukukhwaskira mapulogalamu agho ghalipo kale.
Seti ya Character
[lemba | kulemba source]Malembo ghakwamba gha C source character set ni nthe malemba agha:
- Malembo gha Lowercase na uppercase gha ISO basic Latin alphabet:
a
–z
,A
–Z
- vipendo vya Decimal:
0
–9
- vilemba vyakubeka (Graphic characters):
! " # % & ' ( ) * + , - . / : ; < = > ? [ \ ] ^ _ { | } ~
- malemba ghambula kubekeka (Whitespace characters): space, horizontal tab, vertical tab, form feed, newline
Chimanyikwiro cha mzere uphya chikulongora umaliro wa mzere wa malembo; likwenera yayi kuyana na lizgu limoza leneco, nangauli kuti liŵe lakunozga C wakuliwona nthena.
Malembo ghanyake ghakulembeka na ma byte ghanandi ghangaseŵezeskeka mu string literals , kweni ghakunyamulika yayi . Muyezo wasonosono wa C ( C11 ) ukuzomerezga kuti malembo gha Unicode gha vyaru vinandi ghaŵikike mwakunyamulika mukati mwa malembo gha C source mwa kugwiliskira nchito \uXXXX
panji \UXXXXXXXX
kuŵika makodi (apo X
ghakulongora chilembo cha hexadecimal), nangauli chinthu ichi chindagwiriskike nchito chomene.[needs update]
Mazgu ghakwamba gha C ghakukomeka ghali na malembo ghakuyana waka, pamoza na vithuzithuzi vya chenjezgo , backspace , na kuwelera kwa galimoto . Wovwiri wa nyengo yakuchimbira wa malembo ghakusazgikira wasazgikira na kusintha kulikose kwa muyezo wa C.
Mazgu ghakusungika
[lemba | kulemba source]Mazgu agho ghakulondezgapo ghakulembeka na vilembo vichokovichoko.
C89 ili na mazgu 32 ghakusungika, agho ghakumanyikwaso kuti ‘mazgu ghakuzirwa’, agho ghangagwiliskirika nchito yayi pa vinthu vinyake padera pa ivyo ghali kulongosoreka kale:
C89 ili na mazgu 32 ghakusungika, agho ghakumanyikwaso kuti ‘mazgu ghakuzirwa’, agho ghangagwiliskirika nchito yayi pa vinthu vinyake padera pa ivyo ghali kulongosoreka kale
inline
restrict
_Bool
‡_Complex
_Imaginary
C11 wakasazgapo mazgu ghanyake ghankhondi na ghaŵiri ghakusungika: (‡ yikulongora zina linyake lakulembera lizgu lakuzirwa la C23)
_Alignas
‡_Alignof
‡_Atomic
_Generic
_Noreturn
_Static_assert
‡_Thread_local
‡
C23 wakasunga mazgu ghanyake khumi na ghankhondi:
alignas
alignof
bool
constexpr
false
nullptr
static_assert
thread_local
true
typeof
typeof_unqual
_BitInt
_Decimal32
_Decimal64
_Decimal128
Mazgu ghanandi agho ghasungika sonosono apa ghakwamba na mzere wakulembeka pasi ndipo pamanyuma pake pali chilembo chikuru, chifukwa vimanyikwiro vya fomu iyo vikasungika kale na C standard kuti vigwiriskike nchito waka na kukhazikiska. Pakuti source code ya pulogiramu iyo yilipo yikwenera yayi kugwiliskira nchito vimanyikwiro ivi, yingakhwaskika yayi apo C implementations yikwamba kukhozgera vigaŵa ivi vya chiyowoyero cha pulogiramu. Mitu yinyake yakumanyikwa yikulongosora mazgu ghakuyana waka gha vimanyikwiro vyakulembeka pasi. Mazgu ghanyake ghakasazgikirapo nga ni mazgu ghakuzirwa na malembo ghawo ghakumanyikwa mu C23 ndipo macros ghakuyana waka ghakafumiskikapo.
Pambere C89, entry
wakasungika nga ni lizgu lakuzirwa. Mu buku lawo lachiŵiri la The C Programming Language , ilo likulongosora ivyo vikamanyikwa kuti C89, Kernighan na Ritchie ŵakalemba kuti, "The ... [mazgu ghakuzirwa] entry
, kale ghakasungika kweni ghakagwiriskirika nchito yayi, ghakusungikaso yayi." na " entry
Lizgu lakuzirwa lakubabika wakufwa likufumiskikapo."
Ma Operators
[lemba | kulemba source]C supports a rich set of operators , iyo ni vimanyikwiro ivyo vikugwiriskirika nchito mukati mwa mazgu kuti vilongosore ivyo vikwenera kuchitika apo ŵakuwunika mazgu agha. C wali na Ma Operators agha:
- kupenda:
+
,-
,*
,/
,%
- kuyaniska:
=
- augmented assignment: Template:Codes
- bitwise logic:
~
,&
,|
,^
- bitwise shifts:
<<
,>>
- Boolean logic:
!
,&&
,||
- conditional evaluation:
? :
- equality testing:
==
,!=
- calling functions:
( )
- increment and decrement:
++
,--
- member selection:
.
,->
- object size:
sizeof
- type:
typeof
,typeof_unqual
since C23 - order relations:
<
,<=
,>
,>=
- reference and dereference:
&
,*
,[ ]
- sequencing:
,
- subexpression grouping:
( )
- type conversion:
(typename)
C wakugwiriskira ncito operator =
(wakugwiriskira ncito mu masamu kurongora kuyana) kurongora mulimo, kulondezga ciyerezgero ca Fortran na PL/I , kweni mwakupambana na ALGOL na vyakufumapo vyake. C wakugwiriskira ncito opareshoni ==
kuti wayezge usange ŵakuyana waka. Kufanana pakati pa awo ŵakugwira ntchito pa kugaŵira na kulinganiska kungapangiska kuti ŵagwiriskirenge ncito mwangozi yumoza mu malo gha munyake, ndipo nyengo zinandi kupuvya kukupangiska uthenga wakubudika yayi (nangauli ŵanyake awo ŵakuwunganya ŵakupanga chenjezgo). Mwaciyerezgero, mazgu ghakuti conditional if (a == b + 1)
ghangalembeka mwambura kwenelera nga ni if (a = b + 1)
, agho ghazamupimika nga ni true
kwambura kuti mtengo wa a
uli 0
pamanyuma pa mulimo.[20]
C operator pakwamba nyengo zose nchakupulikikwa yayi. Mwachiyelezgero, uyo wakugwira ntchito ==
wakukaka chomene kuluska (wakuchitika pambere) awo ŵakugwira ntchito &
(bitwise AND) na |
(bitwise OR) mu mazgu nga ni x & 1 == 0
, agho ghakwenera kulembeka nga ni (x & 1) == 0
para ndivyo wakulemba code wakukhumba.[21]
"Hello, world" chiyelezgero
[lemba | kulemba source]Chiyelezgero cha "hello, world" icho chikawoneka mu buku lakwamba la K&R chazgoka chiyelezgero cha pulogiramu yakwamba mu mabuku ghanandi ghakusambizga vya pulogiramu. Pulogalamu iyi yikusindikizga "hello, world" ku mtundu wakumanyikwa , uwo kanandi ukuŵa pa terminal panji pa skrini.
Mtundu wakwamba ukaŵa wakuti:[22]
main()
{
printf("hello, world\n");
}
Pulogalamu yakukolerana na ndondomeko ya "hello, world" ni:[lower-alpha 1]
#include <stdio.h>
int main(void)
{
printf("hello, world\n");
}
Mzere wakwamba wa pulogiramu iyi uli na preprocessing directive, agho ghakulongoreka na #include
. ci cikupangiska kuti wakulemba waŵikepo mzere wa khodi uwo na mazgu ghose gha mu stdio.h
fayilo ya mutu, agho ghali na vimanyikwiro vya milimo ya kunjilirapo na kufumamo nga ni printf
na scanf
. The angle brackets surrounding stdio.h
ghakulongora kuti fayilo ya mutu yingasangika mwakugwiliskira nchito nthowa yakupenjera iyo yikutemwa mitu iyo yikupelekeka na compiler ku mitu yinyake iyo yili na zina limoza (kupambana na makoti ghaŵiri agho kanandi ghakusazgapo mafayilo gha mutu gha ku malo panji gha pulojekiti).
Mzere wachiŵiri ukulongora kuti ntchito iyo yili na zina main
yikulongosoreka. Ntchito iyi main
yikugwira ntchito yapadera mu mapulogalamu gha C; malo gha nyengo yakuchitira vinthu ghakuchema main
ntchito kuti yimbe kuchita pulogiramu. Mtundu wakulongosora int
ukulongora kuti mtengo uwo ukuwelera kwa wakuchema (mu nkhani iyi malo gha nyengo yakuchitira) chifukwa cha kuwunika main
ntchito, ni nambala yakukwana. Lizgu lakuzirwa void
nga ni mndandanda wa parameter likulongora kuti main
ntchito yikutora yayi mphindano.
Brace yakujulika yakukhotakhota yikulongora kwamba kwa khodi ilo likulongosora main
function.
Mzere wakulondezgapo wa pulogiramu iyi ni mazgu agho ghakuchema (ndiko kuti, ghakupatuska kuchitika) ntchito yakuchemeka printf
, iyo mu nkhani iyi yikupelekeka kufuma ku laibulale ya dongosolo . Mu kuyimbira uku, printf
ntchito yikujumpha (ndiko kuti yikuperekeka na) mphindano yimoza, iyo ni adiresi ya mtundu wakwamba mu chingwe cha literal "hello, world\n"
. Chingwe cha literal ni ndondomeko yambura kumanyikwa iyo yikuŵikika yekha na wakulemba, na vinthu vya mtundu char
na chimanyikwiro cha NULL chaumaliro (ASCII value 0) chikulongora umaliro wa ndondomeko (kuti yizomerezgeke printf
kumanya utali wa chingwe). Chimanyikwiro cha NULL chingalembekaso nga ni ndondomeko ya kutchimbira \0
. The \n
ni ndondomeko ya kutchimbira iyo C yikung’anamura ku chimanyikwiro cha mzere uphya , icho, pa kufumamo, chikulongora umaliro wa mzere wa sono. Mtengo wakuwelera wa printf
ntchito ni wa mtundu int
, kweni ukutayika mwakufwasa chifukwa ukugwiriskirika nchito yayi. (Pulogalamu yakupwelelera comene yingayezga mtengo wakuwelera kuti yiwone usange printf
mulimo uwu wacita makora.) Semicolon ;
yikumara mazgu.
Chingwe chakujalira cha curly chikulongora umaliro wa khodi ya main
ntchito. Malinga na C99 specification na viphya, main
ntchito (kupambana na ntchito yinyake) yizamuweleska mtengo wa 0
para yafika pa }
iyo yikumara ntchito. Mtengo wakuwelera wa 0
ukung’anamulika na ndondomeko ya nyengo yakuchitira nga ni khodi yakufumamo iyo yikulongora kuti ntchito yikuchitika makora.[23]
ma Data types
[lemba | kulemba source]This section needs additional citations for verification. (October 2012) |
type system ya C ni ya static ndipo yili weakly typed, iyo yikuyiyaniska na type system ya ŵazukulu ALGOL nthe Pascal.[24] Pali ma built-in types ya ma integer ya milingo yakupambana-pambana, ya signed na ya unsigned, ma nambala ya floating-point , na ma enumerated types (enum
). Mtundu wa integer char
kanandi ukugwiriskirika nchito pa malembo gha byte yimoza. C99 wakasazgapo mtundu wa data ya Boolean . Paliso mitundu yakufumiramo kusazgapo ma arrays , pointers , marekodi ( struct
), na ma union ( union
).
C kanandi yikugwiriskirika nchito mu mapulogiramu gha ndondomeko zapasi apo kutchimbira kufuma ku ndondomeko ya mtundu kungaŵa kwakukhumbikwa. Munthu uyo wakulemba mabuku wakuyezgayezga kuwoneseska kuti mazgu ghanandi ghakulembeka makora, kweni uyo wakulemba mapulogiramu wangasintha ivyo vikulembeka mu nthowa zakupambanapambana, panji wakugwiliskira ntchito mtundu wa cast kuti wasinthe mwakudunjika mtengo kufuma ku mtundu unyake kuya ku unyake, panji wakugwiliskira ntchito vimanyikwiro panji maunioni kuti wazgoreso vigaŵa ivyo vili pasi . ya chinthu cha data mu nthowa yinyake.
Ŵanyake ŵakuwona kuti C's declaration syntax njambura kupulikikwa, chomenechomene pa vimanyikwiro vya ntchito . (Maghanoghano gha Ritchie ghakaŵa ghakuti ŵapharazge vimanyikwiro mu vigaŵa ivyo vikuyana na kugwiliskira ntchito kwawo: " kupharazga kukulongora kugwiliskira ntchito ".)[25]
Kusintha kwa masamu kwa C kwa nyengo zose kukuzomerezga kuti khodi yiwemi yipangike, kweni nyengo zinyake yingapangiska kuti paŵe vyakuchitika vyambura kulindilirika. Mwachiyelezgero, kuyezgelera manambara ghakukwana ghakusayinirika na ghambura kusayinirika ghakuyana waka kukukhumba kusintha mtengo wakusayinirika kuŵa wambura kusayinirika. Ici cingapangiska kuti paŵe vyakucitika vyambura kulindilirika usange mtengo uwo mwasayinira ngwambura kwenelera.
ma Pointers
[lemba | kulemba source]C yikukhozgera kugwiliskira nchito vimanyikwiro , mtundu wa vimanyikwiro ivyo vikulemba adiresi panji malo gha chinthu panji ntchito mu kukumbukira. Ma pointer ghangafumiskikapo kuti ghasange data iyo yasungika pa adiresi iyo yikulongosoreka, panji kuti yicheme ntchito yakulongosoreka. Ma pointer ghangaseŵezeskeka mwakuseŵezeska ntchito panji masamu gha pointer . Kuyimilira kwa nyengo yakuchimbira kwa mtengo wa pointer kanandi ni adiresi ya memory yambura kupangika (panji yikuwonjezgeka na offset-within-word field), kweni pakuti mtundu wa pointer ukusazgapo mtundu wa chinthu icho chikulongoreka, mazgu ghakusazgapo pointer ghangawoneka na mtundu . pa nyengo yakuwunganya. Pointer arithmetic yikupimika yekha na kukula kwa mtundu wa data wakulongozgeka.
Vimanyikwiro vikugwiriskirika ncito pa vinthu vinandi mu C. Vingwe vya malemba vikusinthika comene mwakugwiliskira ncito vimanyikwiro mu vigaŵa vya malembo. Kugaŵika kwa kukumbukira kwa nkhongono kukuchitika mwakugwiliskira ntchito vimanyikwiro; chakufumapo cha a malloc
kanandi chikuponyeka ku mtundu wa data wa data iyo yikwenera kusungika. Mitundu yinandi ya data, nga ni makuni , yikugwiriskirika ncito comene nga ni struct
vinthu ivyo vikugaŵika mwa nkhongono ivyo vikukolerana pamoza mwakugwiliskira ncito vimanyikwiro. Vimanyikwiro vya vimanyikwiro vinyake kanandi vikugwiriskirika nchito mu magulu gha vigaŵa vinandi na magulu gha struct
vinthu. Vimanyikwiro vya milimo ( vimanyikwiro vya milimo ) ni vyakovwira pakujumpha milimo nga ni mphindano ku milimo ya pamwamba (nga ni qsort panji bsearch ), mu matebulo ghakutumizga , panji nga ni callbacks ku awo ŵakulongozga vyakuchitika .
Muyezo wa null pointer ukulongora mwakudunjika kuti palije malo ghakwenelera. Kufumiskiramo mtengo wa null pointer kukulongosoreka yayi, kanandi kukupangiska kuti paŵe suzgo la kugaŵa . Null pointer values ndizo zikovwira pakulongora milandu yapadera nga ni para palije "next" pointer mu node yaumaliro ya mndandanda wakukolerana , panji nga ni chilongolero cha kubudika kufuma ku milimo yakuwelera vimanyikwiro. Mu vigaŵa vyakwenelera mu source code, nga nkhupeleka ku pointer variable, null pointer constant yingalembeka nga ni 0
, na panji kwambura kuponya mwakudumura ku mtundu wa pointer, nga ni NULL
macro iyo yikulongosoreka na mitu yinandi yakumanyikwa panji, kufuma apo C23 na constant . nullptr
. Mu vigaŵa vyakukhazikika, vimanyikwiro vyambura kanthu vikuwoneka ku false
, apo vimanyikwiro vinyake vyose vikuwoneka ku true
.
Vimanyikwiro vyambura kanthu ( void *
) vikulongora vinthu vya mtundu wambura kumanyikwa, ndipo ntheura vingagwiliskirika nchito nga ni vimanyikwiro vya data vya "generic". Pakuti kukura na mtundu wa chinthu icho chikulongosoreka vikumanyikwa yayi, vimanyikwiro vyambura kanthu vingafumiskikapo yayi, panji masamu ghakulongora pa iwo ghakuzomerezgeka yayi, nangauli vingaŵa vyambura kusuzga (ndipo mu vigaŵa vinandi vikusinthika) ku na kufuma ku chilongolero chinyake chilichose cha chinthu . mutundu.
Kugwiriskira ncito vimanyikwiro mwambura kupwelelera kungaŵa kwakofya. Chifukwa chakuti kanandi ŵakuwonekera yayi, pointer variable yingapangika kuti yilongore malo ghaliyose ghambura kumanyikwa, agho ghangapangiska kuti paŵe vyakuchitika vyambura kukhumbikwa. Nangauli vimanyikwiro ivyo vikugwiriskirika ncito makora vikulongora malo ghakuvikilirika, vingapangika kuti vilongore malo ghambura kuvikilirika mwa kugwiliskira ncito masamu gha vimanyikwiro ghambura kugwira nchito ; vinthu ivyo ŵakulongora vingalutilira kugwiliskirika nchito para vyagaŵika ( dangling pointers ); vingagwiriskikiya nchitu kwambula kuti viŵikika pakwamba ( wild pointers ); panji ŵangapika mwaluŵiro mtengo wambura kuvikilirika mwakugwiliskira nchito cast, union, panji kwizira mu pointer yinyake yakuvunda. Mu vigaŵa vinandi, C wakuzomerezga kugwiliskira ntchito na kusintha pakati pa mitundu ya vimanyikwiro, nangauli ŵakuwunganya ŵakupeleka vyakusankha vyakuwonera vigaŵa vyakupambanapambana. Viyowoyero vinyake vyakupanga mapulogiramu vikumazga masuzgo agha mwa kugwiliskira nchito mitundu yakukanizga comene ya vimanyikwiro.
ma Array
[lemba | kulemba source]Mitundu ya Array mu C ndiyo yikukhazikika, kukura kwakukhazikika uko kukulongosoreka pa nyengo yakuwunganya. Muyezo wa C99 wasonosono ukuzomerezgaso mtundu wa ma array gha utali wakusinthasintha. Kweniso, vingachitikaso kugaŵira chigaŵa cha kukumbukira (cha kukula kwake) pa nyengo yakuchitira, kugwiriskira ntchito malloc
ntchito ya layibulare yakumanyikwa, na kuyiwona nga ni ndondomeko.
Pakuti ma array nyengo zose ghakusangika (mu nchito) kwizira mu vimanyikwiro, ma array ghakusangika kanandi ghakuwonekera yayi pa kukula kwa array iyo yili pasi, nangauli ŵanyake awo ŵakuwunganya ŵangapeleka kuwonekera kwa mphaka nga ni chisankho. Kuswa kwa mphaka ya Array ntheura nkhwamachitiko ndipo kungapangiska kuti paŵe masuzgo ghakupambanapambana, kusazgapo kufika pa memory kwambura kuzomerezgeka, kunanga data, buffer overruns , na kupatulapo nyengo yakuchitira.
C ilije ndondomeko yapadera yakupharazgira ma arrays gha vigaŵa vinandi , kweni m’malo mwake yikuthemba pa kuweleraso mukati mwa mtundu wa ndondomeko kuti yipharazge ma arrays gha ma arrays, agho ghakufiska makora chinthu chimoza. Index values ya "mndandanda wa vigaŵa vinandi" yingaghanaghanirika kuti yikukura mu ndondomeko yikuru ya mzere . Ma array gha vigaŵa vinandi ghakugwiriskirika nchito comene mu ma algorithm gha manambara (comenecomene kufuma ku algebra ya mzere wakugwiriskirika ncito ) kusunga matrices. Kapangidwe ka C array kakuyana makora na mulimo uwu. Kweni, mu mitundu yakwamba ya C mphaka ya mndandanda yikwenera kumanyikwa na mtengo wakukhazikika panji kujumpha mwakudunjika ku ndondomeko yiliyose iyo yikukhumba, ndipo mndandanda wa mndandanda wakukhora ungasangika yayi mwakugwiliskira nchito indexing kaŵiri. (Nthowa yakumazgira ivi yikaŵa yakugaŵira mndandanda na "mzere vector" wakusazgikira wa vimanyikwiro ku mizati.) C99 wakayambiska "mndandanda wa utali wakusintha" uwo ukulongosora nkhani iyi.
Chiyelezgero chakulondezgapo chakugwiriskira ncito C ya mazuŵa ghano (C99 panji pamanyuma) cikulongora kugaŵika kwa mndandanda wa vigaŵa viŵiri pa mulu na kugwiriskira ncito mndandanda wa vigaŵa vinandi vyakuŵikapo vimanyikwiro vyakufikapo (ivyo vingagwiliskira ncito mphaka-kuwoneseska pa ŵanandi ŵa C compilers):
int func(int N, int M)
{
float (*p)[N] [M] = malloc(sizeof *p);
if (p == 0)
return -1;
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++)
(*p)[i] [j] = i + j;
print_array(N, M, p);
free(p);
return 1;
}
Ndipo pano pali kukhazikiska kwakuyana waka pakugwiriskira ncito cigaŵa ca C99 ca Auto VLA: [lower-alpha 2]
int func(int N, int M)
{
// Caution: checks should be made to ensure N*M*sizeof(float) does NOT exceed limitations for auto VLAs and is within available size of stack.
float p[N] [M]; // auto VLA is held on the stack, and sized when the function is invoked
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++)
p[i] [j] = i + j;
print_array(N, M, p);
// no need to free(p) since it will disappear when the function exits, along with the rest of the stack frame
return 1;
}
Kusinthanika kwa Array–pointer
[lemba | kulemba source]Mazgu ghakulembeka pasi x[i]
(apo x
ghakulongora chimanyikwiro) ni shuga wa syntactic wa *(x+i)
. Kugwiriskira ncito cimanyisko ca wakuwunganya ca mtundu wa pointer, adiresi iyo x + i
yikulongora kuti ni adiresi yakwamba yayi (iyo yikulongora na x
) iyo yikusazgikira na i
ma byte, kweni m’malo mwake yikulongosoreka kuti ni adiresi yakwamba iyo yikusazgikira na i
kuchulukiskika na kukula kwa an . chinthu icho x
chikulongora ku. Mwantheura, x[i]
wakusankha i+1
chigaŵa cha th cha ndondomeko.
Kweniso, mu vigaŵa vinandi vyakuyowoya (kupatulika kwakumanyikwa ni nga ni operand ya sizeof
), mazgu gha mtundu wa array ghakusinthika mwaŵene kuŵa pointer ku chinthu chakwamba cha array. Ici cikung'anamura kuti ndondomeko yikukopeka yayi nga ni yose para yacemeka nga ni mphindano ku nchito, kweni m'malo mwake adiresi ya cigaŵa cake cakwamba pera ndiyo yikujumpha. Ntheura, nangauli mafoni ghakugwira ntchito mu C ghakugwiriskira ncito semantics yakujumpha-na-mtengo , ma array ghakujumpha na fundo .
Kukura kwa ndondomeko yose x
kungamanyikwa mwa kugwiriskira ncito sizeof
ku mazgu gha mtundu wa ndondomeko. Kukura kwa chinthu kungamanyikwa pakugwiriskira ntchito opareshoni sizeof
ku chinthu chilichose chakufumiskikapo cha ndondomeko A
, nga umo vikuŵira mu n = sizeof A[0]
. Ntheura, chiŵelengero cha vinthu ivyo vili mu ndondomeko iyo yapharazgika A
chingamanyikwa nga ni sizeof A / sizeof A[0]
. Wonani kuti usange pali waka chimanyikwiro cha chinthu chakwamba nga umo vikuŵira kanandi mu C code chifukwa cha kusintha kwakujiyimira pakwekha uko kwalongosoreka pacanya apa, uthenga wakukhwaskana na mtundu wose wa ndondomeko na utali wake ukutayika.
Kwendeska Memory
[lemba | kulemba source]Chimoza mwa vinthu vinyake vyakuzirwa chomene ivyo chiyowoyero cha pulogiramu chikuchita nkhupeleka malo ghakulongozgera memory na vinthu ivyo vikusungika mu memory. C wakupereka nthowa zitatu zikuru zakugaŵira kukumbukira vinthu:[23]
- Static memory allocation: malo gha chinthu ghakuperekeka mu binary pa nyengo yakusonkheska; vinthu ivi vili na mlingo (panji umoyo) usange binary iyo yili navyo yikuŵikika mu kukumbukira.
- Automatic memory allocation: temporary objects can be stored on the stack, and this space is automatically freed and reusable after the block in which they are declared is exited.
- Dynamic memory allocation: mabuloko ghakukumbukira gha kukula kwake ghangapempheka pa nyengo yakuchitira vinthu mwakugwiliskira ntchito milimo ya layibulare nga ni
malloc
kufuma ku chigaŵa cha kukumbukira icho chikuchemeka heap ; mabuloko agha ghakukhalilira mpaka apo ghazamufwatulika kuti ghagwiriskike nchitoso mwa kucema nchito ya layibularerealloc
panjifree
.
Nthowa zitatu izi ni zakwenelera mu nyengo zakupambanapambana ndipo zili na vyakuguliska vyakupambanapambana. Mwachiyelezgero, kugaŵira kwa kukumbukira kwakukhazikika kuli na mtengo uchoko wakugaŵira, kugaŵira kwakujiyimira paŵekha kungaŵa na mtengo ukuru pachoko, ndipo kugaŵira kwakukumbukira kwakusintha kungaŵa na mtengo ukuru wa kugaŵira na kugaŵira. Kukhalilira kwa vinthu vyambura kusintha nkhwakovwira kusunga uthenga wa boma pa mafoni ghakugwira ntchito, kugaŵira kwakujiyimira pakwekha nkhwambura kusuzga kugwiliskira nchito kweni malo ghakuŵikamo vinthu ghakuŵa ghachoko chomene ndiposo ghakukhala nyengo yichoko waka kuluska malo ghakukumbukira panji gha mulu, ndipo kugaŵira kwakukumbukira kwakukhozga kukuzomerezga kugaŵira vinthu ivyo kukula kwake kukumanyikwa waka pa nyengo yakuchitira. Mapulogalamu ghanandi gha C ghakugwiriskira ncito comene vyose vitatu.
Para nchamachitiko, kugaŵira kwakujiyimira pakwekha panji kwakukhazikika kanandi nkhwambura kusuzga comene cifukwa vyakusungirako vikulaŵilirika na uyo wakulemba, ndipo ivi vikufwatura uyo wakupanga pulogiramu ku mulimo uwo ungaŵa wakubudika wa kugaŵira na kufwatura vyakusungirako na mawoko. Kweni, vigaŵa vinandi vya data vingasinthika mu kukura pa nyengo yakuchitira, ndipo pakuti kugaŵira kwakukhazikika (na kugaŵira kwakujiyimira paŵekha pambere C99 yindafike) kukwenera kuŵa na kukula kwakukhazikika pa nyengo yakuwunganya, pali vinthu vinandi ivyo kugaŵira kwakukhozga kukukhumbikwa. Pambere C99 standard, ma arrays ghakusinthasintha ghakaŵa chiyelezgero chakumanyikwa cha ichi. (Wonani nkhani yakukhwaskana na C dynamic memory allocation kuti muwone chiyelezgero cha ma arrays ghakugaŵika mwakusintha.) Mwakupambana na kugaŵika kwakujiyimira, uko kungatondeka pa nyengo yakuchitira vinthu na vyakuchitika vyambura kumanyikwa, ntchito zakugaŵika zakusintha zikuweleska chimanyikwiro (mu mtundu wa mtengo wa null pointer) apo . malo ghakusungirako ghakukhumbikwa ghangagaŵika yayi. (Static allocation iyo njikuru chomene kanandi yikumanyikwa na linker panji loader , pambere pulogiramu yindambe kugwira ntchito.)
Kupatulapo para vyalembeka vinyake, vinthu vyambura kusintha vikuŵa na zero panji null pointer values para pulogiramu yayamba. Vinthu ivyo vikugaŵika mwaŵene ndiposo mwa nkhongono vikuyambiskika pekha usange mtengo wakwamba ukuyowoyeka mwakudunjika; apo yayi pakwamba ŵali na mtengo wambura kumanyikwa (kaŵirikaŵiri, chilichose icho chikuchitika kuti chiŵepo mu kusungirako , icho chingaŵa kuti chikwimira yayi mtengo wakuzomerezgeka wa mtundu uwo). Usange pulogiramu yikuyezga kusanga mtengo uwo undayambike, ivyo vikufumamo vikumanyikwa yayi. Ŵanthu ŵanandi awo ŵakuwunganya mabuku mazuŵa ghano ŵakuyezgayezga kumanya na kuchenjezga za suzgo ili, kweni vyose viŵiri, viwemi vyautesi na viheni vyautesi vingaŵapo.
Heap memory allocation yikwenera kukolerana na kugwiliskira ntchito kwake kwenikweni mu pulogiramu yiliyose kuti yigwiriskike nchitoso mwakukwana. Mwaciyelezgero, usange cilongolero cimoza pera ca kugaŵira kukumbukira kwa mulu cikufuma mu msinkhu panji mtengo wake ukulembeka pambere undagaŵike mwakudunjika, mbwenu kukumbukira uko kungasangikaso yayi kuti kugwiriskike ncitoso pamanyuma ndipo kukutayika comene ku pulogiramu, cinthu ico cikumanyikwa kuti kukumbukira . nthonya . Mwakupambana, nchamacitiko kuti kukumbukira kuŵe kwakufwatuka, kweni kukuyowoyeka pamanyuma, ndipo kukupangiska kuti paŵe vyakucitika vyambura kumanyikwa. Kanandi, vimanyikwiro vya kutondeka vikuwoneka mu cigaŵa ca pulogiramu ico cikukhwaskana yayi na khodi ilo likupangiska kuti paŵe suzgo, ndipo vikuŵa vyakusuzga kumanya usange vyatondeka. Nkhani zanthena izi zikunozga mu viyowoyero ivyo vikuwuskako viswaswa mwaŵene .
Malaibulale
[lemba | kulemba source]Chiyowoyero cha C chikugwiriskira ncito malaibulale nga ni nthowa yake yikuru yakusazgirako. Mu C, laibulale ni gulu la milimo iyo yili mu fayilo yimoza ya "archive". Laibulale yiliyose kanandi yili na fayilo ya mutu , iyo yili na viyelezgero vya milimo iyo yili mukati mwa layibulare iyo yingagwiliskirika nchito na pulogiramu, na kupharazgira mitundu yapadera ya data na vimanyikwiro vya macro ivyo vikugwiriskirika nchito na milimo iyi. Kuti pulogiramu yigwiriskirenge nchito laibulale, yikwenera kuŵa na fayilo ya mutu wa laibulale, ndipo laibulale yikwenera kukolerana na pulogiramu, iyo mu nyengo zinandi yikukhumba mbendera za compiler (mwachiyelezgero, -lm
, chifupi cha "kulumikiza laibulale ya masamu").
Laibulale ya C yakumanyikwa chomene ni C standard library , iyo yikulongosoreka na ISO na ANSI C standards ndipo yikwiza na kukhazikiska kuli kose kwa C (kukhazikiska uko kukukhwaska malo ghachoko waka nga ni ndondomeko zakuŵikika kungapereka waka chigaŵa chichoko wa laibulale yakumanyikwa). Laibulale iyi yikovwira pa ivyo vikunjilizgika na ivyo vikufumamo, kugaŵira kukumbukira, masamu, vingwe vya malembo, na nyengo. Mitu yinandi yakupambanapambana yakumanyikwa (mwaciyelezgero, stdio.h
) yikulongosora umo vinthu ivi na vinyake vyakumanyikwa vya layibulare vikuŵikika.
Ntchito zinyake zakumanyikwa za C library ni izo zikugwiriskirika nchito na mapulogalamu agho ghakupangika na Unix na Unix-like systems, chomenechomene ntchito izo zikupereka mawonekero ku kernel . Ntchito izi zikulongosoreka mu vigaŵa vyakupambanapambana nga ni POSIX na Single UNIX Specification .
Pakuti mapulogiramu ghanandi ghalembeka mu C, pali malaibulale ghanyake ghakupambanapambana agho ghalipo. Malaibulale kanandi ghakulembeka mu C chifukwa C compilers ŵakupanga khodi ya vinthu yakunozga ; ŵakupanga mapulogalamu ŵakupanga ma interface gha layibulare mwakuti ndondomeko zingagwiliskirika nchito kufuma ku viyowoyero vyapachanya nga ni Java , Perl , na Python.[23]
File handling na streams
[lemba | kulemba source]Fayilo input and output (I / O) ni chigaŵa cha chiyowoyero cha C yayi kweni m'malo mwake chikuchitika na malaibulale (nga ni laibulale ya C standard) na mafayilo ghawo gha mutu wakukolerana (mwachiyelezgero stdio.h
). Kugwiliskira ntchito mafayilo kukuchitika chomene kwizira mu I/O yapachanya iyo yikugwira ntchito kwizira mu milonga . Mtsinje ni kufuma pa fundo iyi data flow iyo yikujiyimira paŵekha na vipangizo, apo fayilo ni chipangizo cha simenti. I / O ya pamwamba yikuchitika kwizira mu kukolerana kwa mlonga na fayilo. Mu laibulale ya C standard, buffer (malo ghakukumbukira panji mzere) yikugwiriskirika nchito kwa kanyengo kuti yisungireko data pambere yindatumizgike ku malo ghakumalizgirapo. Ici cikucepeskako nyengo yakulindilira vipangizo ivyo vikucedwa, mwaciyelezgero, hard drive panji solid-state drive . Ntchito za I / O zapasi ni chigaŵa cha laibulale ya C yayi [ kulongosora kukukhumbikwa ] kweni kanandi zikuŵa chigaŵa cha mapulogalamu gha "bare metal" (mapulogalamu agho ghakujiyimira paŵekha na ndondomeko yiliyose yakugwiliskira ntchito nga ni mapulogalamu ghanandi ghakuŵikika ). Kupatulapo ŵachoko waka, kukhazikiska kukusazgapo I / O ya msinkhu wapansi.
Vipangizo vya chiyowoyero
[lemba | kulemba source]This section needs additional citations for verification. (July 2014) |
A number of tools have been developed to help C programmers find and fix statements with undefined behavior or possibly erroneous expressions, with greater rigor than that provided by the compiler. The tool lint was the first such, leading to many others.
Automated source code checking and auditing are beneficial in any language, and for C many such tools exist, such as Lint. A common practice is to use Lint to detect questionable code when a program is first written. Once a program passes Lint, it is then compiled using the C compiler. Also, many compilers can optionally warn about syntactically valid constructs that are likely to actually be errors. MISRA C is a proprietary set of guidelines to avoid such questionable code, developed for embedded systems.[26]
There are also compilers, libraries, and operating system level mechanisms for performing actions that are not a standard part of C, such as bounds checking for arrays, detection of buffer overflow, serialization, dynamic memory tracking, and automatic garbage collection.
Tools such as Purify or Valgrind and linking with libraries containing special versions of the memory allocation functions can help uncover runtime errors in memory usage.[27][28]
magwiliskiro
[lemba | kulemba source]Chifukwa chakugwiriskira ntchito mu mapulogalamu gha ndondomeko
[lemba | kulemba source]C yikugwiriskirika nchito comene pa kupanga mapulogiramu gha ndondomeko pakukhazikiska ndondomeko zakugwiliskira nchito na ndondomeko zakuŵikika . Ichi nchifukwa cha vifukwa vinandi:
- Chiyowoyero cha C chikuzomerezga kuti vipangizo vya pa pulatifomu na kukumbukira viŵepo na vimanyikwiro na mtundu wa punning , ntheura vinthu vyakukhwaskana na ndondomeko (mwachiyelezgero, Control/Status Registers, I/O registers ) vingaŵikika na kugwiliskirika ntchito na khodi yakulembeka mu C – vikuzomerezga kuti vilongozgeke mwakukwana pa . pulatifomu iyo yikuchitikapo.
- Khodi ilo likupangika pamanyuma pa kuwunganya likukhumba yayi vinthu vinandi vya dongosolo , ndipo lingachemeka kufuma ku khodi yinyake ya boot mu nthowa yakunyoloka – nchakusuzga yayi kuchita.
- Mazgu gha chiyowoyero cha C na mazgu ghakuyowoyeka ghakuwoneka makora pa ndondomeko ya malango gha pulosesa yakukhumbikwa, ndipo chifukwa cha ichi pali nyengo yakuchimbira yichoko yakukhumbikwa pa vinthu vya mu dongosolo – vikuchitika mwaluŵiro ku . koma.
- Pakuti chiyowoyero cha C chili na ŵanthu ŵanandi awo ŵakugwira ntchito, chingagwiliskira ntchito vinthu vinandi ivyo vili mu ma CPU agho ghakukhumbikwa. Pa malo agho CPU yinyake yili na malango ghanandi ghakubisika, chiyowoyero chinyake chingapangika na panji intrinsic functions kuti chigwiriskirenge nchito malango agha – chingagwiliskira nchito pafupifupi vyose ivyo vikukhumbikwa na CPU.
- Chiyowoyero chikupangiska kuti chiŵe chipusu kuŵika vigaŵa pa vigaŵa vya data ya binary, kuzomerezga kuti data yipulikikwe, kulongozgeka na kusintha – yingalemba vigaŵa vya data, nanga ni mafayilo.
- Chiyowoyero ichi chikovwira ŵanthu ŵanandi awo ŵakugwira ntchito, kusazgapo kugwiliskira ntchito vinthu vichokovichoko, kuti ŵaŵe na masamu ghakukwana na maghanoghano, ndipo panji manambara ghakuyandama ghakukura mwakupambanapambana – chingagwiliskira ntchito makora data iyo yili kupangika makora.
- C ni chiyowoyero chichoko chomene, chili na mazgu ghachoko waka, ndipo chilije vinthu vinandi ivyo vikupanga khodi yikuru ya chilato – chikupulikikwa.
- C ili na mazaza ghakudunjika pa kugaŵira na kugaŵira vyakukumbukira, ivyo vikupereka nchito yiwemi na nyengo yakumanyikwa ku milimo ya kukumbukira, kwambura kufipa mtima na vyakuchitika vya nyengo na nyengo vyakusonkheska vyakuvunda - vili na ntchito yakumanyikwa .
- C yikuzomerezga kugwiliskira nchito na kukhazikiska ndondomeko zakupambanapambana za kugaŵira kukumbukira, kusazgapo Template:Khodi na Template:Khodi; nthowa yakunozga chomene na mabwalo; panji mtundu wa OS kernel uwo ungayana na DMA, kugwiliskira nchito mukati mwa kunjilirapo kwakutimbanizgas, panji kuphatikizgika na kukumbukira kwakuwoneka dongosolo.
- Kulingana na linker na malo, C code yingachemaso malaibulale agho ghalembeka mu chiyowoyero cha msonkhano, ndipo yingachemeka kufuma ku chiyowoyero cha msonkhano – yikukolerana makora na khodi yinyake ya pasi.
- C na calling conventions yake na linker structures vikugwiriskirika nchito chomene pamoza na viyowoyero vinyake vyapachanya, na kuchema kose ku C na kufuma ku C kukukhozgeka – vikukolerana makora na khodi yinyake yapachanya.
- C ili na chilengedwe chakukhwima chomene ndiposo chakukwana, kusazgapo malaibulale, mafuremu, ŵakuwunganya vyakujulika, ŵakunozga na vyakugwiriskira ntchito, ndipo ni de facto standard. Vikuwoneka kuti ŵakwendeska galimoto ŵalipo kale mu C, panji kuti pali CPU yakuyana waka nga ni back-end ya C compiler, ntheura pali kuchepeska chikhuŵilizgo cha kusankha chiyowoyero chinyake.
Kugwiriskira ncito mu malaibulale ghakugwiriskira ncito makompyuta ghanandi
[lemba | kulemba source]C yikovwira awo ŵakupanga mapulogiramu kuti ŵapange ndondomeko yiwemi ya ma algorithm na data, chifukwa chigaŵa cha abstraction kufuma ku hardware nchakuwonda, ndipo mtengo wake ngwakuchepa, nthowa yakuzirwa chomene ya mapulogalamu ghakugwiriskira ntchito makompyuta. Mwaciyelezgero, Layibulare ya GNU ya Masamu Ghakukwana, Layibulare ya Sayansi ya GNU, Mathematica, na MATLAB vyose panji vigaŵa vinyake vikulembeka mu C. Viyowoyero vinandi vikukhozgera kucema milimo ya layibulare mu . C, mwachiyelezgero, Python-kukhazikika pa ndondomeko NumPy wakugwiriskira ncito C pa vigaŵa vyakugwira nchito comene na vyakukhwaskana na hardware.
C nga ni chiyowoyero cha pakati
[lemba | kulemba source]C nyengo zinyake yikugwiriskirika nchito nga ni chiyowoyero cha pakati na kukhazikiska viyowoyero vinyake. Nthowa iyi yingagwiliskirika nchito kuti yiŵe yakunyamulika panji yakunozga; pakugwiriskira ncito C nga ni ciyowoyero ca pakati, vipangizo vinyake vyakupangika na makina vikukhumbikwa yayi. C ili na vinthu vinyake, nga ni malango gha mzere-nambala ya preprocessor na makoma ghambura kukhumbikwa ghakusankha ku umaliro wa mindandanda ya initializer, agho ghakovwira kuwunganya khodi iyo yapangika. Kweni vinyake ivyo C wakubudiska vyapangiska kuti paŵe viyowoyero vinyake viyowoyero vya C ivyo vikupangika mwakupambanapambana kuti vigwiriskike nchito nga ni viyowoyero vyapakati, nga ni C--. Kweniso, mabuku ghakuru gha mazuŵa ghano GCC na LLVM ghose ghali na kuyimilira kwapakati uko kuli C yayi, ndipo mabuku agha ghakovwira viyowoyero vinandi kusazgapo C.
Viyowoyero vinyake ivyo vikulembeka mu C
[lemba | kulemba source]Chifukwa chakuti C yikusangika chomene ndiposo yikugwira ntchito makora, ntchakuti ŵakuwunganya mabuku , malaibulale na ŵakung’anamura viyowoyero vinyake vyakupanga mapulogiramu kanandi ŵakuvigwiriskira ntchito mu C. Mwachiyelezgero, kukhazikiska kwa vimanyikwiro vya Python , Perl , Ruby , na PHP vikulembeka mu C.
Kamoza ŵakagwiliskiranga ntchito pakupanga webusayiti
[lemba | kulemba source]Mu mbiri, C nyengo zinyake wakagwiliskiranga ntchito pakupanga webusayiti mwakugwiliskira ntchito Common Gateway Interface (CGI) nga ni "chipata" cha uthenga pakati pa webusayiti, seva, na bulauza. C yingaŵa kuti yikasankhika kuluska viyowoyero vyakung’anamulika chifukwa chakuti yikuchitika mwaluŵiro, yikukhazikika, ndiposo yikusangika pafupifupi pa charu chose. Ntchinthu chakumanyikwaso yayi kuti kupanga mawebusaiti kuchitikenge mu C, ndipo vinyake vinandi vyakupangira mawebusayiti vilipo.
Ma seva gha pa webusayiti
[lemba | kulemba source]Ma seva ghaŵiri ghakumanyikwa chomene gha pa webusayiti , Apache HTTP Server na Nginx , ghose ghalembeka mu C. Ma seva agha ghakukolerana na ndondomeko yakugwiliskira ntchito, kutegherezga pa madowoko gha TCP ghakukhumba vya HTTP, ndipo pamanyuma ghakupereka vinthu vyambura kusintha pa webusayiti, panji kupangiska kuti vinyake vikomeke . viyowoyero vyakugwira ntchito kuti 'vipeleke' vinthu nga ni PHP , ivyo vikulembeka chomene mu C. Nthowa ya C yakupangira vinthu pafupi na chisulo yikupangiska kuti ŵazenge mapulogiramu agha ghakugwira ntchito makora chomene.
ma applications gha End-user
[lemba | kulemba source]C nayo yagwiriskirika ncito comene pakukhazikiska mapulogiramu gha end-user.[29] Kweni, mapulogalamu agha ghangalembekaso mu viyowoyero viphya, vyapachanya.
Ivyo C yingapanga cha
[lemba | kulemba source]nkhongono nge ya assembly kwe upusu wa... assembly
— Dennis Ritchie[30]
Nangauli C waŵa wakumanyikwa, wakukhwaska ndiposo wakupambana comene, kweni wali na viheni, kusazgapo:
- Muyezo wankhongono wakukumbukira ntchito na
malloc
ndipofree
ndiwo wakubudika. Vipusikizgi ni ivi: Memory yikudontha para memory yagaŵirika kweni yikufwatulika yayi; na kufika pa memory iyo yikaŵa kuti yafwatulika kale - The use of pointers and the direct manipulation of memory means corruption of memory is possible, perhaps due to programmer error, or insufficient checking of bad data.
- There is some type checking, but it does not apply to areas like variadic functions, and the type checking can be trivially or inadvertently circumvented. It is weakly typed.
- Since the code generated by the compiler contains few checks itself, there is a burden on the programmer to consider all possible outcomes, to protect against buffer overruns, array bounds checking, stack overflows, memory exhaustion, and consider race conditions, thread isolation, etc.
- The use of pointers and the run-time manipulation of these means there may be two ways to access the same data (aliasing), which is not determinable at compile time. This means that some optimisations that may be available to other languages are not possible in C. FORTRAN is considered faster.
- Some of the standard library functions, e.g.
scanf
or
, can lead to buffer overruns.strncat
- There is limited standardisation in support for low-level variants in generated code, for example: different function calling conventions and ABI; different structure packing conventions; different byte ordering within larger integers (including endianness). In many language implementations, some of these options may be handled with the preprocessor directive
#pragma
,[31][32] and some with additional keywords e.g. use__cdecl
calling convention. But the directive and options are not consistently supported.[33] - String handling using the standard library is code-intensive, with explicit memory management required.
- The language does not directly support object orientation, introspection, run-time expression evaluation, generics, etc.
- There are few guards against inappropriate use of language features, which may lead to unmaintainable code. In particular, the C preprocessor can hide troubling effects such as double evaluation and worse.[34] This facility for tricky code has been celebrated with competitions such as the International Obfuscated C Code Contest and the Underhanded C Contest.
- C lacks standard support for exception handling and only offers return codes for error checking. The
setjmp
andlongjmp
standard library functions have been used[35] to implement a try-catch mechanism via macros.
For some purposes, restricted styles of C have been adopted, e.g. MISRA C or CERT C, in an attempt to reduce the opportunity for bugs. Databases such as CWE attempt to count the ways C etc. has vulnerabilities, along with recommendations for mitigation.
There are tools that can mitigate against some of the drawbacks. Contemporary C compilers include checks which may generate warnings to help identify many potential bugs.
Related languages
[lemba | kulemba source]C has both directly and indirectly influenced many later languages such as C++ and Java.[37] The most pervasive influence has been syntactical; all of the languages mentioned combine the statement and (more or less recognizably) expression syntax of C with type systems, data models or large-scale program structures that differ from those of C, sometimes radically.
Several C or near-C interpreters exist, including Ch and CINT, which can also be used for scripting.
When object-oriented programming languages became popular, C++ and Objective-C were two different extensions of C that provided object-oriented capabilities. Both languages were originally implemented as source-to-source compilers; source code was translated into C, and then compiled with a C compiler.[38]
The C++ programming language (originally named "C with Classes") was devised by Bjarne Stroustrup as an approach to providing object-oriented functionality with a C-like syntax.[39] C++ adds greater typing strength, scoping, and other tools useful in object-oriented programming, and permits generic programming via templates. Nearly a superset of C, C++ now[when?] supports most of C, with a few exceptions.
Objective-C was originally a very "thin" layer on top of C, and remains a strict superset of C that permits object-oriented programming using a hybrid dynamic/static typing paradigm. Objective-C derives its syntax from both C and Smalltalk: syntax that involves preprocessing, expressions, function declarations, and function calls is inherited from C, while the syntax for object-oriented features was originally taken from Smalltalk.
In addition to C++ and Objective-C, Ch, Cilk, and Unified Parallel C are nearly supersets of C.
See also
[lemba | kulemba source]Lua error: bad argument #2 to 'title.new' (unrecognized namespace name 'Portal').
- Compatibility of C and C++
- Comparison of Pascal and C
- Comparison of programming languages
- International Obfuscated C Code Contest
- List of C-family programming languages
- List of C compilers
Notes
[lemba | kulemba source]- ↑ The original example code will compile on most modern compilers that are not in strict standard compliance mode, but it does not fully conform to the requirements of either C89 or C99. In fact, C99 requires that a diagnostic message be produced.
- ↑ Code of
print_array
(not shown) slightly differs,[why?] too.
References
[lemba | kulemba source]- ↑ "The name is based on, and pronounced like the letter C in the English alphabet". the c programming language sound (in American English). English Chinese Dictionary. Archived from the original on Novembala 17, 2022. Retrieved Novembala 17, 2022.
- ↑ Munoz, Daniel. "After All These Years, the World is Still Powered by C Programming | Toptal". Toptal Engineering Blog. Retrieved Juni 15, 2024.
- ↑ "C Language Drops to Lowest Popularity Rating". Developer.com (in American English). Ogasiti 9, 2016. Archived from the original on Ogasiti 22, 2022. Retrieved Ogasiti 1, 2022.
- ↑ 4.0 4.1 4.2 4.3 4.4 4.5 Ritchie (1993)
- ↑ "Programming Language Popularity". 2009. Archived from the original on Janyuwale 16, 2009. Retrieved Janyuwale 16, 2009.
- ↑ "TIOBE Programming Community Index". 2009. Archived from the original on Meyi 4, 2009. Retrieved Meyi 6, 2009.
- ↑ Ward, Terry A. (Ogasiti 1983). "Annotated C / A Bibliography of the C Language". Byte. p. 268. Retrieved Janyuwale 31, 2015.
- ↑ Longola ivyo vyabudika: Invalid
<ref>
tag; no text was provided for refs namedC in a Nutshell
- ↑ "TIOBE Index for September 2024". Archived from the original on Sekutembala 18, 2024. Retrieved Sekutembala 20, 2024.
- ↑ Longola ivyo vyabudika: Invalid
<ref>
tag; no text was provided for refs namedvinsp
- ↑ Ritchie, Dennis. "BCPL to B to C". lysator.liu.se. Archived from the original on Disembala 12, 2019. Retrieved Sekutembala 10, 2019.
- ↑ 12.0 12.1 12.2 12.3 12.4 Jensen, Richard (Disembala 9, 2020). ""A damn stupid thing to do"—the origins of C". Ars Technica (in American English). Archived from the original on Malichi 28, 2022. Retrieved Malichi 28, 2022.
- ↑ 13.0 13.1 Johnson, S. C.; Ritchie, D. M. (1978). "Portability of C Programs and the UNIX System". Bell System Tech. J. 57 (6): 2021–2048. CiteSeerX 10.1.1.138.35. doi:10.1002/j.1538-7305.1978.tb02141.x. ISSN 0005-8580. S2CID 17510065. (Note: The PDF is an OCR scan of the original, and contains a rendering of "IBM 370" as "IBM 310".)
- ↑ McIlroy, M. D. (1987). A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986 (PDF) (Technical report). CSTR. Bell Labs. p. 10. 139. Archived (PDF) from the original on Novembala 11, 2017. Retrieved Febuluwale 1, 2015.
- ↑ "Rationale for American National Standard for Information Systems – Programming Language – C". Archived from the original on Julayi 17, 2024. Retrieved Julayi 17, 2024.
- ↑ C Integrity. International Organization for Standardization. Malichi 30, 1995. Archived from the original on Julayi 25, 2018. Retrieved Julayi 24, 2018.
- ↑ "WG14-N3220 : Working Draft, C2y" (PDF). open-std.org. Febuluwale 21, 2024. Archived (PDF) from the original on Febuluwale 26, 2024.
- ↑ Harbison, Samuel P.; Steele, Guy L. (2002). C: A Reference Manual (5th ed.). Englewood Cliffs, NJ: Prentice Hall. ISBN 978-0-13-089592-9. Contains a BNF grammar for C.
- ↑ Kernighan & Ritchie (1988), p. 192.
- ↑ "10 Common Programming Mistakes in C++". Cs.ucr.edu. Archived from the original on Okutobala 21, 2008. Retrieved Juni 26, 2009.
- ↑ Schultz, Thomas (2004). [[[:Template:GBurl]] C and the 8051] (3rd ed.). Otsego, MI: PageFree Publishing Inc. p. 20. ISBN 978-1-58961-237-2. Retrieved Febuluwale 10, 2012.
{{cite book}}
: Check|url=
value (help) - ↑ Kernighan & Ritchie (1978), p. 6.
- ↑ 23.0 23.1 23.2 Klemens, Ben (2013). 21st Century C. O'Reilly Media. ISBN 978-1-4493-2714-9.
- ↑ Feuer, Alan R.; Gehani, Narain H. (Malichi 1982). "Comparison of the Programming Languages C and Pascal". ACM Computing Surveys. 14 (1): 73–92. doi:10.1145/356869.356872. S2CID 3136859.
- ↑ Kernighan & Ritchie (1988), p. 122.
- ↑ "Man Page for lint (freebsd Section 1)". unix.com. Meyi 24, 2001. Retrieved Julayi 15, 2014.
- ↑ "CS107 Valgrind Memcheck". web.stanford.edu. Retrieved Juni 23, 2023.
- ↑ Hastings, Reed; Joyce, Bob. "Purify: Fast Detection of Memory Leaks and Access Errors" (PDF). Pure Software Inc.: 9.
- ↑ Munoz, Daniel. "After All These Years, the World is Still Powered by C Programming". Toptal Engineering Blog (in English). Retrieved Novembala 17, 2023.
- ↑ Metz, Cade. "Dennis Ritchie: The Shoulders Steve Jobs Stood On". Wired. Archived from the original on Epulelo 12, 2022. Retrieved Epulelo 19, 2022.
- ↑ corob-msft (Malichi 31, 2022). "Pragma directives and the __pragma and _Pragma keywords". Microsoft Learn (in American English). Archived from the original on Sekutembala 24, 2022. Retrieved Sekutembala 24, 2022.
- ↑ "Pragmas (The C Preprocessor)". GCC, the GNU Compiler Collection. Archived from the original on Juni 17, 2002. Retrieved Sekutembala 24, 2022.
- ↑ "Pragmas". Intel C++ Compiler Classic Developer Guide and Reference (in English). Intel. Archived from the original on Epulelo 10, 2022. Retrieved Epulelo 10, 2022.
- ↑ "In praise of the C preprocessor". apenwarr. Ogasiti 13, 2007. Retrieved Julayi 9, 2023.
- ↑ Roberts, Eric S. (Malichi 21, 1989). "Implementing Exceptions in C" (PDF). DEC Systems Research Center. SRC-RR-40. Archived (PDF) from the original on Janyuwale 15, 2017. Retrieved Janyuwale 4, 2022.
- ↑ McMillan, Robert (Ogasiti 1, 2013). "Is Java Losing Its Mojo?". Wired. Archived from the original on Febuluwale 15, 2017. Retrieved Malichi 5, 2017.
- ↑ O'Regan, Gerard (Sekutembala 24, 2015). Pillars of computing : a compendium of select, pivotal technology firms. Springer. ISBN 978-3319214641. OCLC 922324121.
- ↑ Rauchwerger, Lawrence (2004). Languages and compilers for parallel computing : 16th international workshop, LCPC 2003, College Station, TX, USA, October 2–4, 2003 : revised papers. Springer. ISBN 978-3540246442. OCLC 57965544.
- ↑ Stroustrup, Bjarne (1993). "A History of C++: 1979–1991" (PDF). Archived (PDF) from the original on Febuluwale 2, 2019. Retrieved Juni 9, 2011.
Sources
[lemba | kulemba source]- Ritchie, Dennis M. (Malichi 1993). "The Development of the C Language". ACM SIGPLAN Notices. ACM. 28 (3): 201–208. doi:10.1145/155360.155580.
- By courtesy of the author, also at Ritchie, Dennis M. "Chistory". www.bell-labs.com. Retrieved Malichi 29, 2022.
- Ritchie, Dennis M. (1993). "The Development of the C Language". The Second ACM SIGPLAN Conference on History of Programming Languages (HOPL-II). ACM. pp. 201–208. doi:10.1145/154766.155580. ISBN 0-89791-570-4. Archived from the original on Epulelo 11, 2019. Retrieved Novembala 4, 2014.
- Kernighan, Brian W.; Ritchie, Dennis M. (1988). The C Programming Language (2nd ed.). Prentice Hall. ISBN 0-13-110362-8.
Further reading
[lemba | kulemba source]- Plauger, P.J. (1992). The Standard C Library (1 ed.). Prentice Hall. ISBN 978-0131315099. (source)
- Banahan, M.; Brady, D.; Doran, M. (1991). The C Book: Featuring the ANSI C Standard (2 ed.). Addison-Wesley. ISBN 978-0201544336. (free)
- Feuer, Alan R. (1985). The C Puzzle Book (1 ed.). Prentice Hall. ISBN 0131099345.
- Harbison, Samuel; Steele, Guy Jr. (2002). C: A Reference Manual (5 ed.). Pearson. ISBN 978-0130895929. (archive)
- King, K.N. (2008). C Programming: A Modern Approach (2 ed.). W. W. Norton. ISBN 978-0393979503. (archive)
- Griffiths, David; Griffiths, Dawn (2012). Head First C (1 ed.). O'Reilly. ISBN 978-1449399917.
- Perry, Greg; Miller, Dean (2013). C Programming: Absolute Beginner's Guide (3 ed.). Que. ISBN 978-0789751980.
- Deitel, Paul; Deitel, Harvey (2015). C: How to Program (8 ed.). Pearson. ISBN 978-0133976892.
- Gustedt, Jens (2019). Modern C (2 ed.). Manning. ISBN 978-1617295812. (free)
External links
[lemba | kulemba source]- ISO C Working Group official website
- ISO/IEC 9899, publicly available official C documents, including the C99 Rationale
- "C99 with Technical corrigenda TC1, TC2, and TC3 included" (PDF). Archived (PDF) from the original on Okutobala 25, 2007. (3.61 MB)
- comp.lang.c Frequently Asked Questions
- A History of C, by Dennis Ritchie
- C Library Reference and Examples
Template:C programming language Template:Integrated development environments Template:Programming languages
- Pages using deprecated enclose attributes
- Wikipedia articles needing clarification from November 2023
- Harv and Sfn no-target errors
- Short description with empty Wikidata description
- Use mdy dates from October 2024
- Wikipedia articles in need of updating from October 2024
- All Wikipedia articles in need of updating
- Articles needing additional references from October 2012
- Articles needing additional references from July 2014
- All articles with vague or ambiguous time
- Vague or ambiguous time from August 2022
- C (programming language)
- American inventions
- Articles with example C code
- C programming language family
- Cross-platform software
- High-level programming languages
- Procedural programming languages
- Structured programming languages
- Programming languages created in 1972
- Programming languages with an ISO standard
- Statically typed programming languages
- Systems programming languages