cpp.info 234 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522
  1. This is cpp.info, produced by makeinfo version 6.6 from cpp.texi.
  2. Copyright (C) 1987-2019 Free Software Foundation, Inc.
  3. Permission is granted to copy, distribute and/or modify this document
  4. under the terms of the GNU Free Documentation License, Version 1.3 or
  5. any later version published by the Free Software Foundation. A copy of
  6. the license is included in the section entitled "GNU Free Documentation
  7. License".
  8. This manual contains no Invariant Sections. The Front-Cover Texts
  9. are (a) (see below), and the Back-Cover Texts are (b) (see below).
  10. (a) The FSF's Front-Cover Text is:
  11. A GNU Manual
  12. (b) The FSF's Back-Cover Text is:
  13. You have freedom to copy and modify this GNU Manual, like GNU
  14. software. Copies published by the Free Software Foundation raise funds
  15. for GNU development.
  16. INFO-DIR-SECTION Software development
  17. START-INFO-DIR-ENTRY
  18. * Cpp: (cpp). The GNU C preprocessor.
  19. END-INFO-DIR-ENTRY
  20. 
  21. File: cpp.info, Node: Top, Next: Overview, Up: (dir)
  22. The C Preprocessor
  23. ******************
  24. The C preprocessor implements the macro language used to transform C,
  25. C++, and Objective-C programs before they are compiled. It can also be
  26. useful on its own.
  27. * Menu:
  28. * Overview::
  29. * Header Files::
  30. * Macros::
  31. * Conditionals::
  32. * Diagnostics::
  33. * Line Control::
  34. * Pragmas::
  35. * Other Directives::
  36. * Preprocessor Output::
  37. * Traditional Mode::
  38. * Implementation Details::
  39. * Invocation::
  40. * Environment Variables::
  41. * GNU Free Documentation License::
  42. * Index of Directives::
  43. * Option Index::
  44. * Concept Index::
  45. -- The Detailed Node Listing --
  46. Overview
  47. * Character sets::
  48. * Initial processing::
  49. * Tokenization::
  50. * The preprocessing language::
  51. Header Files
  52. * Include Syntax::
  53. * Include Operation::
  54. * Search Path::
  55. * Once-Only Headers::
  56. * Alternatives to Wrapper #ifndef::
  57. * Computed Includes::
  58. * Wrapper Headers::
  59. * System Headers::
  60. Macros
  61. * Object-like Macros::
  62. * Function-like Macros::
  63. * Macro Arguments::
  64. * Stringizing::
  65. * Concatenation::
  66. * Variadic Macros::
  67. * Predefined Macros::
  68. * Undefining and Redefining Macros::
  69. * Directives Within Macro Arguments::
  70. * Macro Pitfalls::
  71. Predefined Macros
  72. * Standard Predefined Macros::
  73. * Common Predefined Macros::
  74. * System-specific Predefined Macros::
  75. * C++ Named Operators::
  76. Macro Pitfalls
  77. * Misnesting::
  78. * Operator Precedence Problems::
  79. * Swallowing the Semicolon::
  80. * Duplication of Side Effects::
  81. * Self-Referential Macros::
  82. * Argument Prescan::
  83. * Newlines in Arguments::
  84. Conditionals
  85. * Conditional Uses::
  86. * Conditional Syntax::
  87. * Deleted Code::
  88. Conditional Syntax
  89. * Ifdef::
  90. * If::
  91. * Defined::
  92. * Else::
  93. * Elif::
  94. Implementation Details
  95. * Implementation-defined behavior::
  96. * Implementation limits::
  97. * Obsolete Features::
  98. Obsolete Features
  99. * Obsolete Features::
  100. Copyright (C) 1987-2019 Free Software Foundation, Inc.
  101. Permission is granted to copy, distribute and/or modify this document
  102. under the terms of the GNU Free Documentation License, Version 1.3 or
  103. any later version published by the Free Software Foundation. A copy of
  104. the license is included in the section entitled "GNU Free Documentation
  105. License".
  106. This manual contains no Invariant Sections. The Front-Cover Texts
  107. are (a) (see below), and the Back-Cover Texts are (b) (see below).
  108. (a) The FSF's Front-Cover Text is:
  109. A GNU Manual
  110. (b) The FSF's Back-Cover Text is:
  111. You have freedom to copy and modify this GNU Manual, like GNU
  112. software. Copies published by the Free Software Foundation raise funds
  113. for GNU development.
  114. 
  115. File: cpp.info, Node: Overview, Next: Header Files, Prev: Top, Up: Top
  116. 1 Overview
  117. **********
  118. The C preprocessor, often known as "cpp", is a "macro processor" that is
  119. used automatically by the C compiler to transform your program before
  120. compilation. It is called a macro processor because it allows you to
  121. define "macros", which are brief abbreviations for longer constructs.
  122. The C preprocessor is intended to be used only with C, C++, and
  123. Objective-C source code. In the past, it has been abused as a general
  124. text processor. It will choke on input which does not obey C's lexical
  125. rules. For example, apostrophes will be interpreted as the beginning of
  126. character constants, and cause errors. Also, you cannot rely on it
  127. preserving characteristics of the input which are not significant to
  128. C-family languages. If a Makefile is preprocessed, all the hard tabs
  129. will be removed, and the Makefile will not work.
  130. Having said that, you can often get away with using cpp on things
  131. which are not C. Other Algol-ish programming languages are often safe
  132. (Ada, etc.) So is assembly, with caution. '-traditional-cpp' mode
  133. preserves more white space, and is otherwise more permissive. Many of
  134. the problems can be avoided by writing C or C++ style comments instead
  135. of native language comments, and keeping macros simple.
  136. Wherever possible, you should use a preprocessor geared to the
  137. language you are writing in. Modern versions of the GNU assembler have
  138. macro facilities. Most high level programming languages have their own
  139. conditional compilation and inclusion mechanism. If all else fails, try
  140. a true general text processor, such as GNU M4.
  141. C preprocessors vary in some details. This manual discusses the GNU
  142. C preprocessor, which provides a small superset of the features of ISO
  143. Standard C. In its default mode, the GNU C preprocessor does not do a
  144. few things required by the standard. These are features which are
  145. rarely, if ever, used, and may cause surprising changes to the meaning
  146. of a program which does not expect them. To get strict ISO Standard C,
  147. you should use the '-std=c90', '-std=c99', '-std=c11' or '-std=c17'
  148. options, depending on which version of the standard you want. To get
  149. all the mandatory diagnostics, you must also use '-pedantic'. *Note
  150. Invocation::.
  151. This manual describes the behavior of the ISO preprocessor. To
  152. minimize gratuitous differences, where the ISO preprocessor's behavior
  153. does not conflict with traditional semantics, the traditional
  154. preprocessor should behave the same way. The various differences that
  155. do exist are detailed in the section *note Traditional Mode::.
  156. For clarity, unless noted otherwise, references to 'CPP' in this
  157. manual refer to GNU CPP.
  158. * Menu:
  159. * Character sets::
  160. * Initial processing::
  161. * Tokenization::
  162. * The preprocessing language::
  163. 
  164. File: cpp.info, Node: Character sets, Next: Initial processing, Up: Overview
  165. 1.1 Character sets
  166. ==================
  167. Source code character set processing in C and related languages is
  168. rather complicated. The C standard discusses two character sets, but
  169. there are really at least four.
  170. The files input to CPP might be in any character set at all. CPP's
  171. very first action, before it even looks for line boundaries, is to
  172. convert the file into the character set it uses for internal processing.
  173. That set is what the C standard calls the "source" character set. It
  174. must be isomorphic with ISO 10646, also known as Unicode. CPP uses the
  175. UTF-8 encoding of Unicode.
  176. The character sets of the input files are specified using the
  177. '-finput-charset=' option.
  178. All preprocessing work (the subject of the rest of this manual) is
  179. carried out in the source character set. If you request textual output
  180. from the preprocessor with the '-E' option, it will be in UTF-8.
  181. After preprocessing is complete, string and character constants are
  182. converted again, into the "execution" character set. This character set
  183. is under control of the user; the default is UTF-8, matching the source
  184. character set. Wide string and character constants have their own
  185. character set, which is not called out specifically in the standard.
  186. Again, it is under control of the user. The default is UTF-16 or
  187. UTF-32, whichever fits in the target's 'wchar_t' type, in the target
  188. machine's byte order.(1) Octal and hexadecimal escape sequences do not
  189. undergo conversion; '\x12' has the value 0x12 regardless of the
  190. currently selected execution character set. All other escapes are
  191. replaced by the character in the source character set that they
  192. represent, then converted to the execution character set, just like
  193. unescaped characters.
  194. In identifiers, characters outside the ASCII range can only be
  195. specified with the '\u' and '\U' escapes, not used directly. If strict
  196. ISO C90 conformance is specified with an option such as '-std=c90', or
  197. '-fno-extended-identifiers' is used, then those escapes are not
  198. permitted in identifiers.
  199. ---------- Footnotes ----------
  200. (1) UTF-16 does not meet the requirements of the C standard for a
  201. wide character set, but the choice of 16-bit 'wchar_t' is enshrined in
  202. some system ABIs so we cannot fix this.
  203. 
  204. File: cpp.info, Node: Initial processing, Next: Tokenization, Prev: Character sets, Up: Overview
  205. 1.2 Initial processing
  206. ======================
  207. The preprocessor performs a series of textual transformations on its
  208. input. These happen before all other processing. Conceptually, they
  209. happen in a rigid order, and the entire file is run through each
  210. transformation before the next one begins. CPP actually does them all
  211. at once, for performance reasons. These transformations correspond
  212. roughly to the first three "phases of translation" described in the C
  213. standard.
  214. 1. The input file is read into memory and broken into lines.
  215. Different systems use different conventions to indicate the end of
  216. a line. GCC accepts the ASCII control sequences 'LF', 'CR LF' and
  217. 'CR' as end-of-line markers. These are the canonical sequences
  218. used by Unix, DOS and VMS, and the classic Mac OS (before OSX)
  219. respectively. You may therefore safely copy source code written on
  220. any of those systems to a different one and use it without
  221. conversion. (GCC may lose track of the current line number if a
  222. file doesn't consistently use one convention, as sometimes happens
  223. when it is edited on computers with different conventions that
  224. share a network file system.)
  225. If the last line of any input file lacks an end-of-line marker, the
  226. end of the file is considered to implicitly supply one. The C
  227. standard says that this condition provokes undefined behavior, so
  228. GCC will emit a warning message.
  229. 2. If trigraphs are enabled, they are replaced by their corresponding
  230. single characters. By default GCC ignores trigraphs, but if you
  231. request a strictly conforming mode with the '-std' option, or you
  232. specify the '-trigraphs' option, then it converts them.
  233. These are nine three-character sequences, all starting with '??',
  234. that are defined by ISO C to stand for single characters. They
  235. permit obsolete systems that lack some of C's punctuation to use C.
  236. For example, '??/' stands for '\', so '??/n' is a character
  237. constant for a newline.
  238. Trigraphs are not popular and many compilers implement them
  239. incorrectly. Portable code should not rely on trigraphs being
  240. either converted or ignored. With '-Wtrigraphs' GCC will warn you
  241. when a trigraph may change the meaning of your program if it were
  242. converted. *Note Wtrigraphs::.
  243. In a string constant, you can prevent a sequence of question marks
  244. from being confused with a trigraph by inserting a backslash
  245. between the question marks, or by separating the string literal at
  246. the trigraph and making use of string literal concatenation.
  247. "(??\?)" is the string '(???)', not '(?]'. Traditional C compilers
  248. do not recognize these idioms.
  249. The nine trigraphs and their replacements are
  250. Trigraph: ??( ??) ??< ??> ??= ??/ ??' ??! ??-
  251. Replacement: [ ] { } # \ ^ | ~
  252. 3. Continued lines are merged into one long line.
  253. A continued line is a line which ends with a backslash, '\'. The
  254. backslash is removed and the following line is joined with the
  255. current one. No space is inserted, so you may split a line
  256. anywhere, even in the middle of a word. (It is generally more
  257. readable to split lines only at white space.)
  258. The trailing backslash on a continued line is commonly referred to
  259. as a "backslash-newline".
  260. If there is white space between a backslash and the end of a line,
  261. that is still a continued line. However, as this is usually the
  262. result of an editing mistake, and many compilers will not accept it
  263. as a continued line, GCC will warn you about it.
  264. 4. All comments are replaced with single spaces.
  265. There are two kinds of comments. "Block comments" begin with '/*'
  266. and continue until the next '*/'. Block comments do not nest:
  267. /* this is /* one comment */ text outside comment
  268. "Line comments" begin with '//' and continue to the end of the
  269. current line. Line comments do not nest either, but it does not
  270. matter, because they would end in the same place anyway.
  271. // this is // one comment
  272. text outside comment
  273. It is safe to put line comments inside block comments, or vice versa.
  274. /* block comment
  275. // contains line comment
  276. yet more comment
  277. */ outside comment
  278. // line comment /* contains block comment */
  279. But beware of commenting out one end of a block comment with a line
  280. comment.
  281. // l.c. /* block comment begins
  282. oops! this isn't a comment anymore */
  283. Comments are not recognized within string literals. "/* blah */" is
  284. the string constant '/* blah */', not an empty string.
  285. Line comments are not in the 1989 edition of the C standard, but they
  286. are recognized by GCC as an extension. In C++ and in the 1999 edition
  287. of the C standard, they are an official part of the language.
  288. Since these transformations happen before all other processing, you
  289. can split a line mechanically with backslash-newline anywhere. You can
  290. comment out the end of a line. You can continue a line comment onto the
  291. next line with backslash-newline. You can even split '/*', '*/', and
  292. '//' onto multiple lines with backslash-newline. For example:
  293. /\
  294. *
  295. */ # /*
  296. */ defi\
  297. ne FO\
  298. O 10\
  299. 20
  300. is equivalent to '#define FOO 1020'. All these tricks are extremely
  301. confusing and should not be used in code intended to be readable.
  302. There is no way to prevent a backslash at the end of a line from
  303. being interpreted as a backslash-newline. This cannot affect any
  304. correct program, however.
  305. 
  306. File: cpp.info, Node: Tokenization, Next: The preprocessing language, Prev: Initial processing, Up: Overview
  307. 1.3 Tokenization
  308. ================
  309. After the textual transformations are finished, the input file is
  310. converted into a sequence of "preprocessing tokens". These mostly
  311. correspond to the syntactic tokens used by the C compiler, but there are
  312. a few differences. White space separates tokens; it is not itself a
  313. token of any kind. Tokens do not have to be separated by white space,
  314. but it is often necessary to avoid ambiguities.
  315. When faced with a sequence of characters that has more than one
  316. possible tokenization, the preprocessor is greedy. It always makes each
  317. token, starting from the left, as big as possible before moving on to
  318. the next token. For instance, 'a+++++b' is interpreted as
  319. 'a ++ ++ + b', not as 'a ++ + ++ b', even though the latter tokenization
  320. could be part of a valid C program and the former could not.
  321. Once the input file is broken into tokens, the token boundaries never
  322. change, except when the '##' preprocessing operator is used to paste
  323. tokens together. *Note Concatenation::. For example,
  324. #define foo() bar
  325. foo()baz
  326. ==> bar baz
  327. _not_
  328. ==> barbaz
  329. The compiler does not re-tokenize the preprocessor's output. Each
  330. preprocessing token becomes one compiler token.
  331. Preprocessing tokens fall into five broad classes: identifiers,
  332. preprocessing numbers, string literals, punctuators, and other. An
  333. "identifier" is the same as an identifier in C: any sequence of letters,
  334. digits, or underscores, which begins with a letter or underscore.
  335. Keywords of C have no significance to the preprocessor; they are
  336. ordinary identifiers. You can define a macro whose name is a keyword,
  337. for instance. The only identifier which can be considered a
  338. preprocessing keyword is 'defined'. *Note Defined::.
  339. This is mostly true of other languages which use the C preprocessor.
  340. However, a few of the keywords of C++ are significant even in the
  341. preprocessor. *Note C++ Named Operators::.
  342. In the 1999 C standard, identifiers may contain letters which are not
  343. part of the "basic source character set", at the implementation's
  344. discretion (such as accented Latin letters, Greek letters, or Chinese
  345. ideograms). This may be done with an extended character set, or the
  346. '\u' and '\U' escape sequences. GCC only accepts such characters in the
  347. '\u' and '\U' forms.
  348. As an extension, GCC treats '$' as a letter. This is for
  349. compatibility with some systems, such as VMS, where '$' is commonly used
  350. in system-defined function and object names. '$' is not a letter in
  351. strictly conforming mode, or if you specify the '-$' option. *Note
  352. Invocation::.
  353. A "preprocessing number" has a rather bizarre definition. The
  354. category includes all the normal integer and floating point constants
  355. one expects of C, but also a number of other things one might not
  356. initially recognize as a number. Formally, preprocessing numbers begin
  357. with an optional period, a required decimal digit, and then continue
  358. with any sequence of letters, digits, underscores, periods, and
  359. exponents. Exponents are the two-character sequences 'e+', 'e-', 'E+',
  360. 'E-', 'p+', 'p-', 'P+', and 'P-'. (The exponents that begin with 'p' or
  361. 'P' are used for hexadecimal floating-point constants.)
  362. The purpose of this unusual definition is to isolate the preprocessor
  363. from the full complexity of numeric constants. It does not have to
  364. distinguish between lexically valid and invalid floating-point numbers,
  365. which is complicated. The definition also permits you to split an
  366. identifier at any position and get exactly two tokens, which can then be
  367. pasted back together with the '##' operator.
  368. It's possible for preprocessing numbers to cause programs to be
  369. misinterpreted. For example, '0xE+12' is a preprocessing number which
  370. does not translate to any valid numeric constant, therefore a syntax
  371. error. It does not mean '0xE + 12', which is what you might have
  372. intended.
  373. "String literals" are string constants, character constants, and
  374. header file names (the argument of '#include').(1) String constants and
  375. character constants are straightforward: "..." or '...'. In either case
  376. embedded quotes should be escaped with a backslash: '\'' is the
  377. character constant for '''. There is no limit on the length of a
  378. character constant, but the value of a character constant that contains
  379. more than one character is implementation-defined. *Note Implementation
  380. Details::.
  381. Header file names either look like string constants, "...", or are
  382. written with angle brackets instead, <...>. In either case, backslash
  383. is an ordinary character. There is no way to escape the closing quote
  384. or angle bracket. The preprocessor looks for the header file in
  385. different places depending on which form you use. *Note Include
  386. Operation::.
  387. No string literal may extend past the end of a line. You may use
  388. continued lines instead, or string constant concatenation.
  389. "Punctuators" are all the usual bits of punctuation which are
  390. meaningful to C and C++. All but three of the punctuation characters in
  391. ASCII are C punctuators. The exceptions are '@', '$', and '`'. In
  392. addition, all the two- and three-character operators are punctuators.
  393. There are also six "digraphs", which the C++ standard calls "alternative
  394. tokens", which are merely alternate ways to spell other punctuators.
  395. This is a second attempt to work around missing punctuation in obsolete
  396. systems. It has no negative side effects, unlike trigraphs, but does
  397. not cover as much ground. The digraphs and their corresponding normal
  398. punctuators are:
  399. Digraph: <% %> <: :> %: %:%:
  400. Punctuator: { } [ ] # ##
  401. Any other single character is considered "other". It is passed on to
  402. the preprocessor's output unmolested. The C compiler will almost
  403. certainly reject source code containing "other" tokens. In ASCII, the
  404. only other characters are '@', '$', '`', and control characters other
  405. than NUL (all bits zero). (Note that '$' is normally considered a
  406. letter.) All characters with the high bit set (numeric range 0x7F-0xFF)
  407. are also "other" in the present implementation. This will change when
  408. proper support for international character sets is added to GCC.
  409. NUL is a special case because of the high probability that its
  410. appearance is accidental, and because it may be invisible to the user
  411. (many terminals do not display NUL at all). Within comments, NULs are
  412. silently ignored, just as any other character would be. In running
  413. text, NUL is considered white space. For example, these two directives
  414. have the same meaning.
  415. #define X^@1
  416. #define X 1
  417. (where '^@' is ASCII NUL). Within string or character constants, NULs
  418. are preserved. In the latter two cases the preprocessor emits a warning
  419. message.
  420. ---------- Footnotes ----------
  421. (1) The C standard uses the term "string literal" to refer only to
  422. what we are calling "string constants".
  423. 
  424. File: cpp.info, Node: The preprocessing language, Prev: Tokenization, Up: Overview
  425. 1.4 The preprocessing language
  426. ==============================
  427. After tokenization, the stream of tokens may simply be passed straight
  428. to the compiler's parser. However, if it contains any operations in the
  429. "preprocessing language", it will be transformed first. This stage
  430. corresponds roughly to the standard's "translation phase 4" and is what
  431. most people think of as the preprocessor's job.
  432. The preprocessing language consists of "directives" to be executed
  433. and "macros" to be expanded. Its primary capabilities are:
  434. * Inclusion of header files. These are files of declarations that
  435. can be substituted into your program.
  436. * Macro expansion. You can define "macros", which are abbreviations
  437. for arbitrary fragments of C code. The preprocessor will replace
  438. the macros with their definitions throughout the program. Some
  439. macros are automatically defined for you.
  440. * Conditional compilation. You can include or exclude parts of the
  441. program according to various conditions.
  442. * Line control. If you use a program to combine or rearrange source
  443. files into an intermediate file which is then compiled, you can use
  444. line control to inform the compiler where each source line
  445. originally came from.
  446. * Diagnostics. You can detect problems at compile time and issue
  447. errors or warnings.
  448. There are a few more, less useful, features.
  449. Except for expansion of predefined macros, all these operations are
  450. triggered with "preprocessing directives". Preprocessing directives are
  451. lines in your program that start with '#'. Whitespace is allowed before
  452. and after the '#'. The '#' is followed by an identifier, the "directive
  453. name". It specifies the operation to perform. Directives are commonly
  454. referred to as '#NAME' where NAME is the directive name. For example,
  455. '#define' is the directive that defines a macro.
  456. The '#' which begins a directive cannot come from a macro expansion.
  457. Also, the directive name is not macro expanded. Thus, if 'foo' is
  458. defined as a macro expanding to 'define', that does not make '#foo' a
  459. valid preprocessing directive.
  460. The set of valid directive names is fixed. Programs cannot define
  461. new preprocessing directives.
  462. Some directives require arguments; these make up the rest of the
  463. directive line and must be separated from the directive name by
  464. whitespace. For example, '#define' must be followed by a macro name and
  465. the intended expansion of the macro.
  466. A preprocessing directive cannot cover more than one line. The line
  467. may, however, be continued with backslash-newline, or by a block comment
  468. which extends past the end of the line. In either case, when the
  469. directive is processed, the continuations have already been merged with
  470. the first line to make one long line.
  471. 
  472. File: cpp.info, Node: Header Files, Next: Macros, Prev: Overview, Up: Top
  473. 2 Header Files
  474. **************
  475. A header file is a file containing C declarations and macro definitions
  476. (*note Macros::) to be shared between several source files. You request
  477. the use of a header file in your program by "including" it, with the C
  478. preprocessing directive '#include'.
  479. Header files serve two purposes.
  480. * System header files declare the interfaces to parts of the
  481. operating system. You include them in your program to supply the
  482. definitions and declarations you need to invoke system calls and
  483. libraries.
  484. * Your own header files contain declarations for interfaces between
  485. the source files of your program. Each time you have a group of
  486. related declarations and macro definitions all or most of which are
  487. needed in several different source files, it is a good idea to
  488. create a header file for them.
  489. Including a header file produces the same results as copying the
  490. header file into each source file that needs it. Such copying would be
  491. time-consuming and error-prone. With a header file, the related
  492. declarations appear in only one place. If they need to be changed, they
  493. can be changed in one place, and programs that include the header file
  494. will automatically use the new version when next recompiled. The header
  495. file eliminates the labor of finding and changing all the copies as well
  496. as the risk that a failure to find one copy will result in
  497. inconsistencies within a program.
  498. In C, the usual convention is to give header files names that end
  499. with '.h'. It is most portable to use only letters, digits, dashes, and
  500. underscores in header file names, and at most one dot.
  501. * Menu:
  502. * Include Syntax::
  503. * Include Operation::
  504. * Search Path::
  505. * Once-Only Headers::
  506. * Alternatives to Wrapper #ifndef::
  507. * Computed Includes::
  508. * Wrapper Headers::
  509. * System Headers::
  510. 
  511. File: cpp.info, Node: Include Syntax, Next: Include Operation, Up: Header Files
  512. 2.1 Include Syntax
  513. ==================
  514. Both user and system header files are included using the preprocessing
  515. directive '#include'. It has two variants:
  516. '#include <FILE>'
  517. This variant is used for system header files. It searches for a
  518. file named FILE in a standard list of system directories. You can
  519. prepend directories to this list with the '-I' option (*note
  520. Invocation::).
  521. '#include "FILE"'
  522. This variant is used for header files of your own program. It
  523. searches for a file named FILE first in the directory containing
  524. the current file, then in the quote directories and then the same
  525. directories used for '<FILE>'. You can prepend directories to the
  526. list of quote directories with the '-iquote' option.
  527. The argument of '#include', whether delimited with quote marks or
  528. angle brackets, behaves like a string constant in that comments are not
  529. recognized, and macro names are not expanded. Thus, '#include <x/*y>'
  530. specifies inclusion of a system header file named 'x/*y'.
  531. However, if backslashes occur within FILE, they are considered
  532. ordinary text characters, not escape characters. None of the character
  533. escape sequences appropriate to string constants in C are processed.
  534. Thus, '#include "x\n\\y"' specifies a filename containing three
  535. backslashes. (Some systems interpret '\' as a pathname separator. All
  536. of these also interpret '/' the same way. It is most portable to use
  537. only '/'.)
  538. It is an error if there is anything (other than comments) on the line
  539. after the file name.
  540. 
  541. File: cpp.info, Node: Include Operation, Next: Search Path, Prev: Include Syntax, Up: Header Files
  542. 2.2 Include Operation
  543. =====================
  544. The '#include' directive works by directing the C preprocessor to scan
  545. the specified file as input before continuing with the rest of the
  546. current file. The output from the preprocessor contains the output
  547. already generated, followed by the output resulting from the included
  548. file, followed by the output that comes from the text after the
  549. '#include' directive. For example, if you have a header file 'header.h'
  550. as follows,
  551. char *test (void);
  552. and a main program called 'program.c' that uses the header file, like
  553. this,
  554. int x;
  555. #include "header.h"
  556. int
  557. main (void)
  558. {
  559. puts (test ());
  560. }
  561. the compiler will see the same token stream as it would if 'program.c'
  562. read
  563. int x;
  564. char *test (void);
  565. int
  566. main (void)
  567. {
  568. puts (test ());
  569. }
  570. Included files are not limited to declarations and macro definitions;
  571. those are merely the typical uses. Any fragment of a C program can be
  572. included from another file. The include file could even contain the
  573. beginning of a statement that is concluded in the containing file, or
  574. the end of a statement that was started in the including file. However,
  575. an included file must consist of complete tokens. Comments and string
  576. literals which have not been closed by the end of an included file are
  577. invalid. For error recovery, they are considered to end at the end of
  578. the file.
  579. To avoid confusion, it is best if header files contain only complete
  580. syntactic units--function declarations or definitions, type
  581. declarations, etc.
  582. The line following the '#include' directive is always treated as a
  583. separate line by the C preprocessor, even if the included file lacks a
  584. final newline.
  585. 
  586. File: cpp.info, Node: Search Path, Next: Once-Only Headers, Prev: Include Operation, Up: Header Files
  587. 2.3 Search Path
  588. ===============
  589. By default, the preprocessor looks for header files included by the
  590. quote form of the directive '#include "FILE"' first relative to the
  591. directory of the current file, and then in a preconfigured list of
  592. standard system directories. For example, if '/usr/include/sys/stat.h'
  593. contains '#include "types.h"', GCC looks for 'types.h' first in
  594. '/usr/include/sys', then in its usual search path.
  595. For the angle-bracket form '#include <FILE>', the preprocessor's
  596. default behavior is to look only in the standard system directories.
  597. The exact search directory list depends on the target system, how GCC is
  598. configured, and where it is installed. You can find the default search
  599. directory list for your version of CPP by invoking it with the '-v'
  600. option. For example,
  601. cpp -v /dev/null -o /dev/null
  602. There are a number of command-line options you can use to add
  603. additional directories to the search path. The most commonly-used
  604. option is '-IDIR', which causes DIR to be searched after the current
  605. directory (for the quote form of the directive) and ahead of the
  606. standard system directories. You can specify multiple '-I' options on
  607. the command line, in which case the directories are searched in
  608. left-to-right order.
  609. If you need separate control over the search paths for the quote and
  610. angle-bracket forms of the '#include' directive, you can use the
  611. '-iquote' and/or '-isystem' options instead of '-I'. *Note
  612. Invocation::, for a detailed description of these options, as well as
  613. others that are less generally useful.
  614. If you specify other options on the command line, such as '-I', that
  615. affect where the preprocessor searches for header files, the directory
  616. list printed by the '-v' option reflects the actual search path used by
  617. the preprocessor.
  618. Note that you can also prevent the preprocessor from searching any of
  619. the default system header directories with the '-nostdinc' option. This
  620. is useful when you are compiling an operating system kernel or some
  621. other program that does not use the standard C library facilities, or
  622. the standard C library itself.
  623. 
  624. File: cpp.info, Node: Once-Only Headers, Next: Alternatives to Wrapper #ifndef, Prev: Search Path, Up: Header Files
  625. 2.4 Once-Only Headers
  626. =====================
  627. If a header file happens to be included twice, the compiler will process
  628. its contents twice. This is very likely to cause an error, e.g. when
  629. the compiler sees the same structure definition twice. Even if it does
  630. not, it will certainly waste time.
  631. The standard way to prevent this is to enclose the entire real
  632. contents of the file in a conditional, like this:
  633. /* File foo. */
  634. #ifndef FILE_FOO_SEEN
  635. #define FILE_FOO_SEEN
  636. THE ENTIRE FILE
  637. #endif /* !FILE_FOO_SEEN */
  638. This construct is commonly known as a "wrapper #ifndef". When the
  639. header is included again, the conditional will be false, because
  640. 'FILE_FOO_SEEN' is defined. The preprocessor will skip over the entire
  641. contents of the file, and the compiler will not see it twice.
  642. CPP optimizes even further. It remembers when a header file has a
  643. wrapper '#ifndef'. If a subsequent '#include' specifies that header,
  644. and the macro in the '#ifndef' is still defined, it does not bother to
  645. rescan the file at all.
  646. You can put comments outside the wrapper. They will not interfere
  647. with this optimization.
  648. The macro 'FILE_FOO_SEEN' is called the "controlling macro" or "guard
  649. macro". In a user header file, the macro name should not begin with
  650. '_'. In a system header file, it should begin with '__' to avoid
  651. conflicts with user programs. In any kind of header file, the macro
  652. name should contain the name of the file and some additional text, to
  653. avoid conflicts with other header files.
  654. 
  655. File: cpp.info, Node: Alternatives to Wrapper #ifndef, Next: Computed Includes, Prev: Once-Only Headers, Up: Header Files
  656. 2.5 Alternatives to Wrapper #ifndef
  657. ===================================
  658. CPP supports two more ways of indicating that a header file should be
  659. read only once. Neither one is as portable as a wrapper '#ifndef' and
  660. we recommend you do not use them in new programs, with the caveat that
  661. '#import' is standard practice in Objective-C.
  662. CPP supports a variant of '#include' called '#import' which includes
  663. a file, but does so at most once. If you use '#import' instead of
  664. '#include', then you don't need the conditionals inside the header file
  665. to prevent multiple inclusion of the contents. '#import' is standard in
  666. Objective-C, but is considered a deprecated extension in C and C++.
  667. '#import' is not a well designed feature. It requires the users of a
  668. header file to know that it should only be included once. It is much
  669. better for the header file's implementor to write the file so that users
  670. don't need to know this. Using a wrapper '#ifndef' accomplishes this
  671. goal.
  672. In the present implementation, a single use of '#import' will prevent
  673. the file from ever being read again, by either '#import' or '#include'.
  674. You should not rely on this; do not use both '#import' and '#include' to
  675. refer to the same header file.
  676. Another way to prevent a header file from being included more than
  677. once is with the '#pragma once' directive (*note Pragmas::). '#pragma
  678. once' does not have the problems that '#import' does, but it is not
  679. recognized by all preprocessors, so you cannot rely on it in a portable
  680. program.
  681. 
  682. File: cpp.info, Node: Computed Includes, Next: Wrapper Headers, Prev: Alternatives to Wrapper #ifndef, Up: Header Files
  683. 2.6 Computed Includes
  684. =====================
  685. Sometimes it is necessary to select one of several different header
  686. files to be included into your program. They might specify
  687. configuration parameters to be used on different sorts of operating
  688. systems, for instance. You could do this with a series of conditionals,
  689. #if SYSTEM_1
  690. # include "system_1.h"
  691. #elif SYSTEM_2
  692. # include "system_2.h"
  693. #elif SYSTEM_3
  694. ...
  695. #endif
  696. That rapidly becomes tedious. Instead, the preprocessor offers the
  697. ability to use a macro for the header name. This is called a "computed
  698. include". Instead of writing a header name as the direct argument of
  699. '#include', you simply put a macro name there instead:
  700. #define SYSTEM_H "system_1.h"
  701. ...
  702. #include SYSTEM_H
  703. 'SYSTEM_H' will be expanded, and the preprocessor will look for
  704. 'system_1.h' as if the '#include' had been written that way originally.
  705. 'SYSTEM_H' could be defined by your Makefile with a '-D' option.
  706. You must be careful when you define the macro. '#define' saves
  707. tokens, not text. The preprocessor has no way of knowing that the macro
  708. will be used as the argument of '#include', so it generates ordinary
  709. tokens, not a header name. This is unlikely to cause problems if you
  710. use double-quote includes, which are close enough to string constants.
  711. If you use angle brackets, however, you may have trouble.
  712. The syntax of a computed include is actually a bit more general than
  713. the above. If the first non-whitespace character after '#include' is
  714. not '"' or '<', then the entire line is macro-expanded like running text
  715. would be.
  716. If the line expands to a single string constant, the contents of that
  717. string constant are the file to be included. CPP does not re-examine
  718. the string for embedded quotes, but neither does it process backslash
  719. escapes in the string. Therefore
  720. #define HEADER "a\"b"
  721. #include HEADER
  722. looks for a file named 'a\"b'. CPP searches for the file according to
  723. the rules for double-quoted includes.
  724. If the line expands to a token stream beginning with a '<' token and
  725. including a '>' token, then the tokens between the '<' and the first '>'
  726. are combined to form the filename to be included. Any whitespace
  727. between tokens is reduced to a single space; then any space after the
  728. initial '<' is retained, but a trailing space before the closing '>' is
  729. ignored. CPP searches for the file according to the rules for
  730. angle-bracket includes.
  731. In either case, if there are any tokens on the line after the file
  732. name, an error occurs and the directive is not processed. It is also an
  733. error if the result of expansion does not match either of the two
  734. expected forms.
  735. These rules are implementation-defined behavior according to the C
  736. standard. To minimize the risk of different compilers interpreting your
  737. computed includes differently, we recommend you use only a single
  738. object-like macro which expands to a string constant. This will also
  739. minimize confusion for people reading your program.
  740. 
  741. File: cpp.info, Node: Wrapper Headers, Next: System Headers, Prev: Computed Includes, Up: Header Files
  742. 2.7 Wrapper Headers
  743. ===================
  744. Sometimes it is necessary to adjust the contents of a system-provided
  745. header file without editing it directly. GCC's 'fixincludes' operation
  746. does this, for example. One way to do that would be to create a new
  747. header file with the same name and insert it in the search path before
  748. the original header. That works fine as long as you're willing to
  749. replace the old header entirely. But what if you want to refer to the
  750. old header from the new one?
  751. You cannot simply include the old header with '#include'. That will
  752. start from the beginning, and find your new header again. If your
  753. header is not protected from multiple inclusion (*note Once-Only
  754. Headers::), it will recurse infinitely and cause a fatal error.
  755. You could include the old header with an absolute pathname:
  756. #include "/usr/include/old-header.h"
  757. This works, but is not clean; should the system headers ever move, you
  758. would have to edit the new headers to match.
  759. There is no way to solve this problem within the C standard, but you
  760. can use the GNU extension '#include_next'. It means, "Include the
  761. _next_ file with this name". This directive works like '#include'
  762. except in searching for the specified file: it starts searching the list
  763. of header file directories _after_ the directory in which the current
  764. file was found.
  765. Suppose you specify '-I /usr/local/include', and the list of
  766. directories to search also includes '/usr/include'; and suppose both
  767. directories contain 'signal.h'. Ordinary '#include <signal.h>' finds
  768. the file under '/usr/local/include'. If that file contains
  769. '#include_next <signal.h>', it starts searching after that directory,
  770. and finds the file in '/usr/include'.
  771. '#include_next' does not distinguish between '<FILE>' and '"FILE"'
  772. inclusion, nor does it check that the file you specify has the same name
  773. as the current file. It simply looks for the file named, starting with
  774. the directory in the search path after the one where the current file
  775. was found.
  776. The use of '#include_next' can lead to great confusion. We recommend
  777. it be used only when there is no other alternative. In particular, it
  778. should not be used in the headers belonging to a specific program; it
  779. should be used only to make global corrections along the lines of
  780. 'fixincludes'.
  781. 
  782. File: cpp.info, Node: System Headers, Prev: Wrapper Headers, Up: Header Files
  783. 2.8 System Headers
  784. ==================
  785. The header files declaring interfaces to the operating system and
  786. runtime libraries often cannot be written in strictly conforming C.
  787. Therefore, GCC gives code found in "system headers" special treatment.
  788. All warnings, other than those generated by '#warning' (*note
  789. Diagnostics::), are suppressed while GCC is processing a system header.
  790. Macros defined in a system header are immune to a few warnings wherever
  791. they are expanded. This immunity is granted on an ad-hoc basis, when we
  792. find that a warning generates lots of false positives because of code in
  793. macros defined in system headers.
  794. Normally, only the headers found in specific directories are
  795. considered system headers. These directories are determined when GCC is
  796. compiled. There are, however, two ways to make normal headers into
  797. system headers:
  798. * Header files found in directories added to the search path with the
  799. '-isystem' and '-idirafter' command-line options are treated as
  800. system headers for the purposes of diagnostics.
  801. * There is also a directive, '#pragma GCC system_header', which tells
  802. GCC to consider the rest of the current include file a system
  803. header, no matter where it was found. Code that comes before the
  804. '#pragma' in the file is not affected. '#pragma GCC system_header'
  805. has no effect in the primary source file.
  806. On some targets, such as RS/6000 AIX, GCC implicitly surrounds all
  807. system headers with an 'extern "C"' block when compiling as C++.
  808. 
  809. File: cpp.info, Node: Macros, Next: Conditionals, Prev: Header Files, Up: Top
  810. 3 Macros
  811. ********
  812. A "macro" is a fragment of code which has been given a name. Whenever
  813. the name is used, it is replaced by the contents of the macro. There
  814. are two kinds of macros. They differ mostly in what they look like when
  815. they are used. "Object-like" macros resemble data objects when used,
  816. "function-like" macros resemble function calls.
  817. You may define any valid identifier as a macro, even if it is a C
  818. keyword. The preprocessor does not know anything about keywords. This
  819. can be useful if you wish to hide a keyword such as 'const' from an
  820. older compiler that does not understand it. However, the preprocessor
  821. operator 'defined' (*note Defined::) can never be defined as a macro,
  822. and C++'s named operators (*note C++ Named Operators::) cannot be macros
  823. when you are compiling C++.
  824. * Menu:
  825. * Object-like Macros::
  826. * Function-like Macros::
  827. * Macro Arguments::
  828. * Stringizing::
  829. * Concatenation::
  830. * Variadic Macros::
  831. * Predefined Macros::
  832. * Undefining and Redefining Macros::
  833. * Directives Within Macro Arguments::
  834. * Macro Pitfalls::
  835. 
  836. File: cpp.info, Node: Object-like Macros, Next: Function-like Macros, Up: Macros
  837. 3.1 Object-like Macros
  838. ======================
  839. An "object-like macro" is a simple identifier which will be replaced by
  840. a code fragment. It is called object-like because it looks like a data
  841. object in code that uses it. They are most commonly used to give
  842. symbolic names to numeric constants.
  843. You create macros with the '#define' directive. '#define' is
  844. followed by the name of the macro and then the token sequence it should
  845. be an abbreviation for, which is variously referred to as the macro's
  846. "body", "expansion" or "replacement list". For example,
  847. #define BUFFER_SIZE 1024
  848. defines a macro named 'BUFFER_SIZE' as an abbreviation for the token
  849. '1024'. If somewhere after this '#define' directive there comes a C
  850. statement of the form
  851. foo = (char *) malloc (BUFFER_SIZE);
  852. then the C preprocessor will recognize and "expand" the macro
  853. 'BUFFER_SIZE'. The C compiler will see the same tokens as it would if
  854. you had written
  855. foo = (char *) malloc (1024);
  856. By convention, macro names are written in uppercase. Programs are
  857. easier to read when it is possible to tell at a glance which names are
  858. macros.
  859. The macro's body ends at the end of the '#define' line. You may
  860. continue the definition onto multiple lines, if necessary, using
  861. backslash-newline. When the macro is expanded, however, it will all
  862. come out on one line. For example,
  863. #define NUMBERS 1, \
  864. 2, \
  865. 3
  866. int x[] = { NUMBERS };
  867. ==> int x[] = { 1, 2, 3 };
  868. The most common visible consequence of this is surprising line numbers
  869. in error messages.
  870. There is no restriction on what can go in a macro body provided it
  871. decomposes into valid preprocessing tokens. Parentheses need not
  872. balance, and the body need not resemble valid C code. (If it does not,
  873. you may get error messages from the C compiler when you use the macro.)
  874. The C preprocessor scans your program sequentially. Macro
  875. definitions take effect at the place you write them. Therefore, the
  876. following input to the C preprocessor
  877. foo = X;
  878. #define X 4
  879. bar = X;
  880. produces
  881. foo = X;
  882. bar = 4;
  883. When the preprocessor expands a macro name, the macro's expansion
  884. replaces the macro invocation, then the expansion is examined for more
  885. macros to expand. For example,
  886. #define TABLESIZE BUFSIZE
  887. #define BUFSIZE 1024
  888. TABLESIZE
  889. ==> BUFSIZE
  890. ==> 1024
  891. 'TABLESIZE' is expanded first to produce 'BUFSIZE', then that macro is
  892. expanded to produce the final result, '1024'.
  893. Notice that 'BUFSIZE' was not defined when 'TABLESIZE' was defined.
  894. The '#define' for 'TABLESIZE' uses exactly the expansion you specify--in
  895. this case, 'BUFSIZE'--and does not check to see whether it too contains
  896. macro names. Only when you _use_ 'TABLESIZE' is the result of its
  897. expansion scanned for more macro names.
  898. This makes a difference if you change the definition of 'BUFSIZE' at
  899. some point in the source file. 'TABLESIZE', defined as shown, will
  900. always expand using the definition of 'BUFSIZE' that is currently in
  901. effect:
  902. #define BUFSIZE 1020
  903. #define TABLESIZE BUFSIZE
  904. #undef BUFSIZE
  905. #define BUFSIZE 37
  906. Now 'TABLESIZE' expands (in two stages) to '37'.
  907. If the expansion of a macro contains its own name, either directly or
  908. via intermediate macros, it is not expanded again when the expansion is
  909. examined for more macros. This prevents infinite recursion. *Note
  910. Self-Referential Macros::, for the precise details.
  911. 
  912. File: cpp.info, Node: Function-like Macros, Next: Macro Arguments, Prev: Object-like Macros, Up: Macros
  913. 3.2 Function-like Macros
  914. ========================
  915. You can also define macros whose use looks like a function call. These
  916. are called "function-like macros". To define a function-like macro, you
  917. use the same '#define' directive, but you put a pair of parentheses
  918. immediately after the macro name. For example,
  919. #define lang_init() c_init()
  920. lang_init()
  921. ==> c_init()
  922. A function-like macro is only expanded if its name appears with a
  923. pair of parentheses after it. If you write just the name, it is left
  924. alone. This can be useful when you have a function and a macro of the
  925. same name, and you wish to use the function sometimes.
  926. extern void foo(void);
  927. #define foo() /* optimized inline version */
  928. ...
  929. foo();
  930. funcptr = foo;
  931. Here the call to 'foo()' will use the macro, but the function pointer
  932. will get the address of the real function. If the macro were to be
  933. expanded, it would cause a syntax error.
  934. If you put spaces between the macro name and the parentheses in the
  935. macro definition, that does not define a function-like macro, it defines
  936. an object-like macro whose expansion happens to begin with a pair of
  937. parentheses.
  938. #define lang_init () c_init()
  939. lang_init()
  940. ==> () c_init()()
  941. The first two pairs of parentheses in this expansion come from the
  942. macro. The third is the pair that was originally after the macro
  943. invocation. Since 'lang_init' is an object-like macro, it does not
  944. consume those parentheses.
  945. 
  946. File: cpp.info, Node: Macro Arguments, Next: Stringizing, Prev: Function-like Macros, Up: Macros
  947. 3.3 Macro Arguments
  948. ===================
  949. Function-like macros can take "arguments", just like true functions. To
  950. define a macro that uses arguments, you insert "parameters" between the
  951. pair of parentheses in the macro definition that make the macro
  952. function-like. The parameters must be valid C identifiers, separated by
  953. commas and optionally whitespace.
  954. To invoke a macro that takes arguments, you write the name of the
  955. macro followed by a list of "actual arguments" in parentheses, separated
  956. by commas. The invocation of the macro need not be restricted to a
  957. single logical line--it can cross as many lines in the source file as
  958. you wish. The number of arguments you give must match the number of
  959. parameters in the macro definition. When the macro is expanded, each
  960. use of a parameter in its body is replaced by the tokens of the
  961. corresponding argument. (You need not use all of the parameters in the
  962. macro body.)
  963. As an example, here is a macro that computes the minimum of two
  964. numeric values, as it is defined in many C programs, and some uses.
  965. #define min(X, Y) ((X) < (Y) ? (X) : (Y))
  966. x = min(a, b); ==> x = ((a) < (b) ? (a) : (b));
  967. y = min(1, 2); ==> y = ((1) < (2) ? (1) : (2));
  968. z = min(a + 28, *p); ==> z = ((a + 28) < (*p) ? (a + 28) : (*p));
  969. (In this small example you can already see several of the dangers of
  970. macro arguments. *Note Macro Pitfalls::, for detailed explanations.)
  971. Leading and trailing whitespace in each argument is dropped, and all
  972. whitespace between the tokens of an argument is reduced to a single
  973. space. Parentheses within each argument must balance; a comma within
  974. such parentheses does not end the argument. However, there is no
  975. requirement for square brackets or braces to balance, and they do not
  976. prevent a comma from separating arguments. Thus,
  977. macro (array[x = y, x + 1])
  978. passes two arguments to 'macro': 'array[x = y' and 'x + 1]'. If you
  979. want to supply 'array[x = y, x + 1]' as an argument, you can write it as
  980. 'array[(x = y, x + 1)]', which is equivalent C code.
  981. All arguments to a macro are completely macro-expanded before they
  982. are substituted into the macro body. After substitution, the complete
  983. text is scanned again for macros to expand, including the arguments.
  984. This rule may seem strange, but it is carefully designed so you need not
  985. worry about whether any function call is actually a macro invocation.
  986. You can run into trouble if you try to be too clever, though. *Note
  987. Argument Prescan::, for detailed discussion.
  988. For example, 'min (min (a, b), c)' is first expanded to
  989. min (((a) < (b) ? (a) : (b)), (c))
  990. and then to
  991. ((((a) < (b) ? (a) : (b))) < (c)
  992. ? (((a) < (b) ? (a) : (b)))
  993. : (c))
  994. (Line breaks shown here for clarity would not actually be generated.)
  995. You can leave macro arguments empty; this is not an error to the
  996. preprocessor (but many macros will then expand to invalid code). You
  997. cannot leave out arguments entirely; if a macro takes two arguments,
  998. there must be exactly one comma at the top level of its argument list.
  999. Here are some silly examples using 'min':
  1000. min(, b) ==> (( ) < (b) ? ( ) : (b))
  1001. min(a, ) ==> ((a ) < ( ) ? (a ) : ( ))
  1002. min(,) ==> (( ) < ( ) ? ( ) : ( ))
  1003. min((,),) ==> (((,)) < ( ) ? ((,)) : ( ))
  1004. min() error-> macro "min" requires 2 arguments, but only 1 given
  1005. min(,,) error-> macro "min" passed 3 arguments, but takes just 2
  1006. Whitespace is not a preprocessing token, so if a macro 'foo' takes
  1007. one argument, 'foo ()' and 'foo ( )' both supply it an empty argument.
  1008. Previous GNU preprocessor implementations and documentation were
  1009. incorrect on this point, insisting that a function-like macro that takes
  1010. a single argument be passed a space if an empty argument was required.
  1011. Macro parameters appearing inside string literals are not replaced by
  1012. their corresponding actual arguments.
  1013. #define foo(x) x, "x"
  1014. foo(bar) ==> bar, "x"
  1015. 
  1016. File: cpp.info, Node: Stringizing, Next: Concatenation, Prev: Macro Arguments, Up: Macros
  1017. 3.4 Stringizing
  1018. ===============
  1019. Sometimes you may want to convert a macro argument into a string
  1020. constant. Parameters are not replaced inside string constants, but you
  1021. can use the '#' preprocessing operator instead. When a macro parameter
  1022. is used with a leading '#', the preprocessor replaces it with the
  1023. literal text of the actual argument, converted to a string constant.
  1024. Unlike normal parameter replacement, the argument is not macro-expanded
  1025. first. This is called "stringizing".
  1026. There is no way to combine an argument with surrounding text and
  1027. stringize it all together. Instead, you can write a series of adjacent
  1028. string constants and stringized arguments. The preprocessor replaces
  1029. the stringized arguments with string constants. The C compiler then
  1030. combines all the adjacent string constants into one long string.
  1031. Here is an example of a macro definition that uses stringizing:
  1032. #define WARN_IF(EXP) \
  1033. do { if (EXP) \
  1034. fprintf (stderr, "Warning: " #EXP "\n"); } \
  1035. while (0)
  1036. WARN_IF (x == 0);
  1037. ==> do { if (x == 0)
  1038. fprintf (stderr, "Warning: " "x == 0" "\n"); } while (0);
  1039. The argument for 'EXP' is substituted once, as-is, into the 'if'
  1040. statement, and once, stringized, into the argument to 'fprintf'. If 'x'
  1041. were a macro, it would be expanded in the 'if' statement, but not in the
  1042. string.
  1043. The 'do' and 'while (0)' are a kludge to make it possible to write
  1044. 'WARN_IF (ARG);', which the resemblance of 'WARN_IF' to a function would
  1045. make C programmers want to do; see *note Swallowing the Semicolon::.
  1046. Stringizing in C involves more than putting double-quote characters
  1047. around the fragment. The preprocessor backslash-escapes the quotes
  1048. surrounding embedded string constants, and all backslashes within string
  1049. and character constants, in order to get a valid C string constant with
  1050. the proper contents. Thus, stringizing 'p = "foo\n";' results in
  1051. "p = \"foo\\n\";". However, backslashes that are not inside string or
  1052. character constants are not duplicated: '\n' by itself stringizes to
  1053. "\n".
  1054. All leading and trailing whitespace in text being stringized is
  1055. ignored. Any sequence of whitespace in the middle of the text is
  1056. converted to a single space in the stringized result. Comments are
  1057. replaced by whitespace long before stringizing happens, so they never
  1058. appear in stringized text.
  1059. There is no way to convert a macro argument into a character
  1060. constant.
  1061. If you want to stringize the result of expansion of a macro argument,
  1062. you have to use two levels of macros.
  1063. #define xstr(s) str(s)
  1064. #define str(s) #s
  1065. #define foo 4
  1066. str (foo)
  1067. ==> "foo"
  1068. xstr (foo)
  1069. ==> xstr (4)
  1070. ==> str (4)
  1071. ==> "4"
  1072. 's' is stringized when it is used in 'str', so it is not
  1073. macro-expanded first. But 's' is an ordinary argument to 'xstr', so it
  1074. is completely macro-expanded before 'xstr' itself is expanded (*note
  1075. Argument Prescan::). Therefore, by the time 'str' gets to its argument,
  1076. it has already been macro-expanded.
  1077. 
  1078. File: cpp.info, Node: Concatenation, Next: Variadic Macros, Prev: Stringizing, Up: Macros
  1079. 3.5 Concatenation
  1080. =================
  1081. It is often useful to merge two tokens into one while expanding macros.
  1082. This is called "token pasting" or "token concatenation". The '##'
  1083. preprocessing operator performs token pasting. When a macro is
  1084. expanded, the two tokens on either side of each '##' operator are
  1085. combined into a single token, which then replaces the '##' and the two
  1086. original tokens in the macro expansion. Usually both will be
  1087. identifiers, or one will be an identifier and the other a preprocessing
  1088. number. When pasted, they make a longer identifier. This isn't the
  1089. only valid case. It is also possible to concatenate two numbers (or a
  1090. number and a name, such as '1.5' and 'e3') into a number. Also,
  1091. multi-character operators such as '+=' can be formed by token pasting.
  1092. However, two tokens that don't together form a valid token cannot be
  1093. pasted together. For example, you cannot concatenate 'x' with '+' in
  1094. either order. If you try, the preprocessor issues a warning and emits
  1095. the two tokens. Whether it puts white space between the tokens is
  1096. undefined. It is common to find unnecessary uses of '##' in complex
  1097. macros. If you get this warning, it is likely that you can simply
  1098. remove the '##'.
  1099. Both the tokens combined by '##' could come from the macro body, but
  1100. you could just as well write them as one token in the first place.
  1101. Token pasting is most useful when one or both of the tokens comes from a
  1102. macro argument. If either of the tokens next to an '##' is a parameter
  1103. name, it is replaced by its actual argument before '##' executes. As
  1104. with stringizing, the actual argument is not macro-expanded first. If
  1105. the argument is empty, that '##' has no effect.
  1106. Keep in mind that the C preprocessor converts comments to whitespace
  1107. before macros are even considered. Therefore, you cannot create a
  1108. comment by concatenating '/' and '*'. You can put as much whitespace
  1109. between '##' and its operands as you like, including comments, and you
  1110. can put comments in arguments that will be concatenated. However, it is
  1111. an error if '##' appears at either end of a macro body.
  1112. Consider a C program that interprets named commands. There probably
  1113. needs to be a table of commands, perhaps an array of structures declared
  1114. as follows:
  1115. struct command
  1116. {
  1117. char *name;
  1118. void (*function) (void);
  1119. };
  1120. struct command commands[] =
  1121. {
  1122. { "quit", quit_command },
  1123. { "help", help_command },
  1124. ...
  1125. };
  1126. It would be cleaner not to have to give each command name twice, once
  1127. in the string constant and once in the function name. A macro which
  1128. takes the name of a command as an argument can make this unnecessary.
  1129. The string constant can be created with stringizing, and the function
  1130. name by concatenating the argument with '_command'. Here is how it is
  1131. done:
  1132. #define COMMAND(NAME) { #NAME, NAME ## _command }
  1133. struct command commands[] =
  1134. {
  1135. COMMAND (quit),
  1136. COMMAND (help),
  1137. ...
  1138. };
  1139. 
  1140. File: cpp.info, Node: Variadic Macros, Next: Predefined Macros, Prev: Concatenation, Up: Macros
  1141. 3.6 Variadic Macros
  1142. ===================
  1143. A macro can be declared to accept a variable number of arguments much as
  1144. a function can. The syntax for defining the macro is similar to that of
  1145. a function. Here is an example:
  1146. #define eprintf(...) fprintf (stderr, __VA_ARGS__)
  1147. This kind of macro is called "variadic". When the macro is invoked,
  1148. all the tokens in its argument list after the last named argument (this
  1149. macro has none), including any commas, become the "variable argument".
  1150. This sequence of tokens replaces the identifier '__VA_ARGS__' in the
  1151. macro body wherever it appears. Thus, we have this expansion:
  1152. eprintf ("%s:%d: ", input_file, lineno)
  1153. ==> fprintf (stderr, "%s:%d: ", input_file, lineno)
  1154. The variable argument is completely macro-expanded before it is
  1155. inserted into the macro expansion, just like an ordinary argument. You
  1156. may use the '#' and '##' operators to stringize the variable argument or
  1157. to paste its leading or trailing token with another token. (But see
  1158. below for an important special case for '##'.)
  1159. If your macro is complicated, you may want a more descriptive name
  1160. for the variable argument than '__VA_ARGS__'. CPP permits this, as an
  1161. extension. You may write an argument name immediately before the '...';
  1162. that name is used for the variable argument. The 'eprintf' macro above
  1163. could be written
  1164. #define eprintf(args...) fprintf (stderr, args)
  1165. using this extension. You cannot use '__VA_ARGS__' and this extension
  1166. in the same macro.
  1167. You can have named arguments as well as variable arguments in a
  1168. variadic macro. We could define 'eprintf' like this, instead:
  1169. #define eprintf(format, ...) fprintf (stderr, format, __VA_ARGS__)
  1170. This formulation looks more descriptive, but historically it was less
  1171. flexible: you had to supply at least one argument after the format
  1172. string. In standard C, you could not omit the comma separating the
  1173. named argument from the variable arguments. (Note that this restriction
  1174. has been lifted in C++2a, and never existed in GNU C; see below.)
  1175. Furthermore, if you left the variable argument empty, you would have
  1176. gotten a syntax error, because there would have been an extra comma
  1177. after the format string.
  1178. eprintf("success!\n", );
  1179. ==> fprintf(stderr, "success!\n", );
  1180. This has been fixed in C++2a, and GNU CPP also has a pair of
  1181. extensions which deal with this problem.
  1182. First, in GNU CPP, and in C++ beginning in C++2a, you are allowed to
  1183. leave the variable argument out entirely:
  1184. eprintf ("success!\n")
  1185. ==> fprintf(stderr, "success!\n", );
  1186. Second, C++2a introduces the '__VA_OPT__' function macro. This macro
  1187. may only appear in the definition of a variadic macro. If the variable
  1188. argument has any tokens, then a '__VA_OPT__' invocation expands to its
  1189. argument; but if the variable argument does not have any tokens, the
  1190. '__VA_OPT__' expands to nothing:
  1191. #define eprintf(format, ...) \
  1192. fprintf (stderr, format __VA_OPT__(,) __VA_ARGS__)
  1193. '__VA_OPT__' is also available in GNU C and GNU C++.
  1194. Historically, GNU CPP has also had another extension to handle the
  1195. trailing comma: the '##' token paste operator has a special meaning when
  1196. placed between a comma and a variable argument. Despite the
  1197. introduction of '__VA_OPT__', this extension remains supported in GNU
  1198. CPP, for backward compatibility. If you write
  1199. #define eprintf(format, ...) fprintf (stderr, format, ##__VA_ARGS__)
  1200. and the variable argument is left out when the 'eprintf' macro is used,
  1201. then the comma before the '##' will be deleted. This does _not_ happen
  1202. if you pass an empty argument, nor does it happen if the token preceding
  1203. '##' is anything other than a comma.
  1204. eprintf ("success!\n")
  1205. ==> fprintf(stderr, "success!\n");
  1206. The above explanation is ambiguous about the case where the only macro
  1207. parameter is a variable arguments parameter, as it is meaningless to try
  1208. to distinguish whether no argument at all is an empty argument or a
  1209. missing argument. CPP retains the comma when conforming to a specific C
  1210. standard. Otherwise the comma is dropped as an extension to the
  1211. standard.
  1212. The C standard mandates that the only place the identifier
  1213. '__VA_ARGS__' can appear is in the replacement list of a variadic macro.
  1214. It may not be used as a macro name, macro argument name, or within a
  1215. different type of macro. It may also be forbidden in open text; the
  1216. standard is ambiguous. We recommend you avoid using it except for its
  1217. defined purpose.
  1218. Likewise, C++ forbids '__VA_OPT__' anywhere outside the replacement
  1219. list of a variadic macro.
  1220. Variadic macros became a standard part of the C language with C99.
  1221. GNU CPP previously supported them with a named variable argument
  1222. ('args...', not '...' and '__VA_ARGS__'), which is still supported for
  1223. backward compatibility.
  1224. 
  1225. File: cpp.info, Node: Predefined Macros, Next: Undefining and Redefining Macros, Prev: Variadic Macros, Up: Macros
  1226. 3.7 Predefined Macros
  1227. =====================
  1228. Several object-like macros are predefined; you use them without
  1229. supplying their definitions. They fall into three classes: standard,
  1230. common, and system-specific.
  1231. In C++, there is a fourth category, the named operators. They act
  1232. like predefined macros, but you cannot undefine them.
  1233. * Menu:
  1234. * Standard Predefined Macros::
  1235. * Common Predefined Macros::
  1236. * System-specific Predefined Macros::
  1237. * C++ Named Operators::
  1238. 
  1239. File: cpp.info, Node: Standard Predefined Macros, Next: Common Predefined Macros, Up: Predefined Macros
  1240. 3.7.1 Standard Predefined Macros
  1241. --------------------------------
  1242. The standard predefined macros are specified by the relevant language
  1243. standards, so they are available with all compilers that implement those
  1244. standards. Older compilers may not provide all of them. Their names
  1245. all start with double underscores.
  1246. '__FILE__'
  1247. This macro expands to the name of the current input file, in the
  1248. form of a C string constant. This is the path by which the
  1249. preprocessor opened the file, not the short name specified in
  1250. '#include' or as the input file name argument. For example,
  1251. '"/usr/local/include/myheader.h"' is a possible expansion of this
  1252. macro.
  1253. '__LINE__'
  1254. This macro expands to the current input line number, in the form of
  1255. a decimal integer constant. While we call it a predefined macro,
  1256. it's a pretty strange macro, since its "definition" changes with
  1257. each new line of source code.
  1258. '__FILE__' and '__LINE__' are useful in generating an error message
  1259. to report an inconsistency detected by the program; the message can
  1260. state the source line at which the inconsistency was detected. For
  1261. example,
  1262. fprintf (stderr, "Internal error: "
  1263. "negative string length "
  1264. "%d at %s, line %d.",
  1265. length, __FILE__, __LINE__);
  1266. An '#include' directive changes the expansions of '__FILE__' and
  1267. '__LINE__' to correspond to the included file. At the end of that file,
  1268. when processing resumes on the input file that contained the '#include'
  1269. directive, the expansions of '__FILE__' and '__LINE__' revert to the
  1270. values they had before the '#include' (but '__LINE__' is then
  1271. incremented by one as processing moves to the line after the
  1272. '#include').
  1273. A '#line' directive changes '__LINE__', and may change '__FILE__' as
  1274. well. *Note Line Control::.
  1275. C99 introduced '__func__', and GCC has provided '__FUNCTION__' for a
  1276. long time. Both of these are strings containing the name of the current
  1277. function (there are slight semantic differences; see the GCC manual).
  1278. Neither of them is a macro; the preprocessor does not know the name of
  1279. the current function. They tend to be useful in conjunction with
  1280. '__FILE__' and '__LINE__', though.
  1281. '__DATE__'
  1282. This macro expands to a string constant that describes the date on
  1283. which the preprocessor is being run. The string constant contains
  1284. eleven characters and looks like '"Feb 12 1996"'. If the day of
  1285. the month is less than 10, it is padded with a space on the left.
  1286. If GCC cannot determine the current date, it will emit a warning
  1287. message (once per compilation) and '__DATE__' will expand to
  1288. '"??? ?? ????"'.
  1289. '__TIME__'
  1290. This macro expands to a string constant that describes the time at
  1291. which the preprocessor is being run. The string constant contains
  1292. eight characters and looks like '"23:59:01"'.
  1293. If GCC cannot determine the current time, it will emit a warning
  1294. message (once per compilation) and '__TIME__' will expand to
  1295. '"??:??:??"'.
  1296. '__STDC__'
  1297. In normal operation, this macro expands to the constant 1, to
  1298. signify that this compiler conforms to ISO Standard C. If GNU CPP
  1299. is used with a compiler other than GCC, this is not necessarily
  1300. true; however, the preprocessor always conforms to the standard
  1301. unless the '-traditional-cpp' option is used.
  1302. This macro is not defined if the '-traditional-cpp' option is used.
  1303. On some hosts, the system compiler uses a different convention,
  1304. where '__STDC__' is normally 0, but is 1 if the user specifies
  1305. strict conformance to the C Standard. CPP follows the host
  1306. convention when processing system header files, but when processing
  1307. user files '__STDC__' is always 1. This has been reported to cause
  1308. problems; for instance, some versions of Solaris provide X Windows
  1309. headers that expect '__STDC__' to be either undefined or 1. *Note
  1310. Invocation::.
  1311. '__STDC_VERSION__'
  1312. This macro expands to the C Standard's version number, a long
  1313. integer constant of the form 'YYYYMML' where YYYY and MM are the
  1314. year and month of the Standard version. This signifies which
  1315. version of the C Standard the compiler conforms to. Like
  1316. '__STDC__', this is not necessarily accurate for the entire
  1317. implementation, unless GNU CPP is being used with GCC.
  1318. The value '199409L' signifies the 1989 C standard as amended in
  1319. 1994, which is the current default; the value '199901L' signifies
  1320. the 1999 revision of the C standard; the value '201112L' signifies
  1321. the 2011 revision of the C standard; the value '201710L' signifies
  1322. the 2017 revision of the C standard (which is otherwise identical
  1323. to the 2011 version apart from correction of defects). An
  1324. unspecified value larger than '201710L' is used for the
  1325. experimental '-std=c2x' and '-std=gnu2x' modes.
  1326. This macro is not defined if the '-traditional-cpp' option is used,
  1327. nor when compiling C++ or Objective-C.
  1328. '__STDC_HOSTED__'
  1329. This macro is defined, with value 1, if the compiler's target is a
  1330. "hosted environment". A hosted environment has the complete
  1331. facilities of the standard C library available.
  1332. '__cplusplus'
  1333. This macro is defined when the C++ compiler is in use. You can use
  1334. '__cplusplus' to test whether a header is compiled by a C compiler
  1335. or a C++ compiler. This macro is similar to '__STDC_VERSION__', in
  1336. that it expands to a version number. Depending on the language
  1337. standard selected, the value of the macro is '199711L' for the 1998
  1338. C++ standard, '201103L' for the 2011 C++ standard, '201402L' for
  1339. the 2014 C++ standard, '201703L' for the 2017 C++ standard, or an
  1340. unspecified value strictly larger than '201703L' for the
  1341. experimental languages enabled by '-std=c++2a' and '-std=gnu++2a'.
  1342. '__OBJC__'
  1343. This macro is defined, with value 1, when the Objective-C compiler
  1344. is in use. You can use '__OBJC__' to test whether a header is
  1345. compiled by a C compiler or an Objective-C compiler.
  1346. '__ASSEMBLER__'
  1347. This macro is defined with value 1 when preprocessing assembly
  1348. language.
  1349. 
  1350. File: cpp.info, Node: Common Predefined Macros, Next: System-specific Predefined Macros, Prev: Standard Predefined Macros, Up: Predefined Macros
  1351. 3.7.2 Common Predefined Macros
  1352. ------------------------------
  1353. The common predefined macros are GNU C extensions. They are available
  1354. with the same meanings regardless of the machine or operating system on
  1355. which you are using GNU C or GNU Fortran. Their names all start with
  1356. double underscores.
  1357. '__COUNTER__'
  1358. This macro expands to sequential integral values starting from 0.
  1359. In conjunction with the '##' operator, this provides a convenient
  1360. means to generate unique identifiers. Care must be taken to ensure
  1361. that '__COUNTER__' is not expanded prior to inclusion of
  1362. precompiled headers which use it. Otherwise, the precompiled
  1363. headers will not be used.
  1364. '__GFORTRAN__'
  1365. The GNU Fortran compiler defines this.
  1366. '__GNUC__'
  1367. '__GNUC_MINOR__'
  1368. '__GNUC_PATCHLEVEL__'
  1369. These macros are defined by all GNU compilers that use the C
  1370. preprocessor: C, C++, Objective-C and Fortran. Their values are
  1371. the major version, minor version, and patch level of the compiler,
  1372. as integer constants. For example, GCC version X.Y.Z defines
  1373. '__GNUC__' to X, '__GNUC_MINOR__' to Y, and '__GNUC_PATCHLEVEL__'
  1374. to Z. These macros are also defined if you invoke the preprocessor
  1375. directly.
  1376. If all you need to know is whether or not your program is being
  1377. compiled by GCC, or a non-GCC compiler that claims to accept the
  1378. GNU C dialects, you can simply test '__GNUC__'. If you need to
  1379. write code which depends on a specific version, you must be more
  1380. careful. Each time the minor version is increased, the patch level
  1381. is reset to zero; each time the major version is increased, the
  1382. minor version and patch level are reset. If you wish to use the
  1383. predefined macros directly in the conditional, you will need to
  1384. write it like this:
  1385. /* Test for GCC > 3.2.0 */
  1386. #if __GNUC__ > 3 || \
  1387. (__GNUC__ == 3 && (__GNUC_MINOR__ > 2 || \
  1388. (__GNUC_MINOR__ == 2 && \
  1389. __GNUC_PATCHLEVEL__ > 0))
  1390. Another approach is to use the predefined macros to calculate a
  1391. single number, then compare that against a threshold:
  1392. #define GCC_VERSION (__GNUC__ * 10000 \
  1393. + __GNUC_MINOR__ * 100 \
  1394. + __GNUC_PATCHLEVEL__)
  1395. ...
  1396. /* Test for GCC > 3.2.0 */
  1397. #if GCC_VERSION > 30200
  1398. Many people find this form easier to understand.
  1399. '__GNUG__'
  1400. The GNU C++ compiler defines this. Testing it is equivalent to
  1401. testing '(__GNUC__ && __cplusplus)'.
  1402. '__STRICT_ANSI__'
  1403. GCC defines this macro if and only if the '-ansi' switch, or a
  1404. '-std' switch specifying strict conformance to some version of ISO
  1405. C or ISO C++, was specified when GCC was invoked. It is defined to
  1406. '1'. This macro exists primarily to direct GNU libc's header files
  1407. to use only definitions found in standard C.
  1408. '__BASE_FILE__'
  1409. This macro expands to the name of the main input file, in the form
  1410. of a C string constant. This is the source file that was specified
  1411. on the command line of the preprocessor or C compiler.
  1412. '__INCLUDE_LEVEL__'
  1413. This macro expands to a decimal integer constant that represents
  1414. the depth of nesting in include files. The value of this macro is
  1415. incremented on every '#include' directive and decremented at the
  1416. end of every included file. It starts out at 0, its value within
  1417. the base file specified on the command line.
  1418. '__ELF__'
  1419. This macro is defined if the target uses the ELF object format.
  1420. '__VERSION__'
  1421. This macro expands to a string constant which describes the version
  1422. of the compiler in use. You should not rely on its contents having
  1423. any particular form, but it can be counted on to contain at least
  1424. the release number.
  1425. '__OPTIMIZE__'
  1426. '__OPTIMIZE_SIZE__'
  1427. '__NO_INLINE__'
  1428. These macros describe the compilation mode. '__OPTIMIZE__' is
  1429. defined in all optimizing compilations. '__OPTIMIZE_SIZE__' is
  1430. defined if the compiler is optimizing for size, not speed.
  1431. '__NO_INLINE__' is defined if no functions will be inlined into
  1432. their callers (when not optimizing, or when inlining has been
  1433. specifically disabled by '-fno-inline').
  1434. These macros cause certain GNU header files to provide optimized
  1435. definitions, using macros or inline functions, of system library
  1436. functions. You should not use these macros in any way unless you
  1437. make sure that programs will execute with the same effect whether
  1438. or not they are defined. If they are defined, their value is 1.
  1439. '__GNUC_GNU_INLINE__'
  1440. GCC defines this macro if functions declared 'inline' will be
  1441. handled in GCC's traditional gnu90 mode. Object files will contain
  1442. externally visible definitions of all functions declared 'inline'
  1443. without 'extern' or 'static'. They will not contain any
  1444. definitions of any functions declared 'extern inline'.
  1445. '__GNUC_STDC_INLINE__'
  1446. GCC defines this macro if functions declared 'inline' will be
  1447. handled according to the ISO C99 or later standards. Object files
  1448. will contain externally visible definitions of all functions
  1449. declared 'extern inline'. They will not contain definitions of any
  1450. functions declared 'inline' without 'extern'.
  1451. If this macro is defined, GCC supports the 'gnu_inline' function
  1452. attribute as a way to always get the gnu90 behavior.
  1453. '__CHAR_UNSIGNED__'
  1454. GCC defines this macro if and only if the data type 'char' is
  1455. unsigned on the target machine. It exists to cause the standard
  1456. header file 'limits.h' to work correctly. You should not use this
  1457. macro yourself; instead, refer to the standard macros defined in
  1458. 'limits.h'.
  1459. '__WCHAR_UNSIGNED__'
  1460. Like '__CHAR_UNSIGNED__', this macro is defined if and only if the
  1461. data type 'wchar_t' is unsigned and the front-end is in C++ mode.
  1462. '__REGISTER_PREFIX__'
  1463. This macro expands to a single token (not a string constant) which
  1464. is the prefix applied to CPU register names in assembly language
  1465. for this target. You can use it to write assembly that is usable
  1466. in multiple environments. For example, in the 'm68k-aout'
  1467. environment it expands to nothing, but in the 'm68k-coff'
  1468. environment it expands to a single '%'.
  1469. '__USER_LABEL_PREFIX__'
  1470. This macro expands to a single token which is the prefix applied to
  1471. user labels (symbols visible to C code) in assembly. For example,
  1472. in the 'm68k-aout' environment it expands to an '_', but in the
  1473. 'm68k-coff' environment it expands to nothing.
  1474. This macro will have the correct definition even if
  1475. '-f(no-)underscores' is in use, but it will not be correct if
  1476. target-specific options that adjust this prefix are used (e.g. the
  1477. OSF/rose '-mno-underscores' option).
  1478. '__SIZE_TYPE__'
  1479. '__PTRDIFF_TYPE__'
  1480. '__WCHAR_TYPE__'
  1481. '__WINT_TYPE__'
  1482. '__INTMAX_TYPE__'
  1483. '__UINTMAX_TYPE__'
  1484. '__SIG_ATOMIC_TYPE__'
  1485. '__INT8_TYPE__'
  1486. '__INT16_TYPE__'
  1487. '__INT32_TYPE__'
  1488. '__INT64_TYPE__'
  1489. '__UINT8_TYPE__'
  1490. '__UINT16_TYPE__'
  1491. '__UINT32_TYPE__'
  1492. '__UINT64_TYPE__'
  1493. '__INT_LEAST8_TYPE__'
  1494. '__INT_LEAST16_TYPE__'
  1495. '__INT_LEAST32_TYPE__'
  1496. '__INT_LEAST64_TYPE__'
  1497. '__UINT_LEAST8_TYPE__'
  1498. '__UINT_LEAST16_TYPE__'
  1499. '__UINT_LEAST32_TYPE__'
  1500. '__UINT_LEAST64_TYPE__'
  1501. '__INT_FAST8_TYPE__'
  1502. '__INT_FAST16_TYPE__'
  1503. '__INT_FAST32_TYPE__'
  1504. '__INT_FAST64_TYPE__'
  1505. '__UINT_FAST8_TYPE__'
  1506. '__UINT_FAST16_TYPE__'
  1507. '__UINT_FAST32_TYPE__'
  1508. '__UINT_FAST64_TYPE__'
  1509. '__INTPTR_TYPE__'
  1510. '__UINTPTR_TYPE__'
  1511. These macros are defined to the correct underlying types for the
  1512. 'size_t', 'ptrdiff_t', 'wchar_t', 'wint_t', 'intmax_t',
  1513. 'uintmax_t', 'sig_atomic_t', 'int8_t', 'int16_t', 'int32_t',
  1514. 'int64_t', 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t',
  1515. 'int_least8_t', 'int_least16_t', 'int_least32_t', 'int_least64_t',
  1516. 'uint_least8_t', 'uint_least16_t', 'uint_least32_t',
  1517. 'uint_least64_t', 'int_fast8_t', 'int_fast16_t', 'int_fast32_t',
  1518. 'int_fast64_t', 'uint_fast8_t', 'uint_fast16_t', 'uint_fast32_t',
  1519. 'uint_fast64_t', 'intptr_t', and 'uintptr_t' typedefs,
  1520. respectively. They exist to make the standard header files
  1521. 'stddef.h', 'stdint.h', and 'wchar.h' work correctly. You should
  1522. not use these macros directly; instead, include the appropriate
  1523. headers and use the typedefs. Some of these macros may not be
  1524. defined on particular systems if GCC does not provide a 'stdint.h'
  1525. header on those systems.
  1526. '__CHAR_BIT__'
  1527. Defined to the number of bits used in the representation of the
  1528. 'char' data type. It exists to make the standard header given
  1529. numerical limits work correctly. You should not use this macro
  1530. directly; instead, include the appropriate headers.
  1531. '__SCHAR_MAX__'
  1532. '__WCHAR_MAX__'
  1533. '__SHRT_MAX__'
  1534. '__INT_MAX__'
  1535. '__LONG_MAX__'
  1536. '__LONG_LONG_MAX__'
  1537. '__WINT_MAX__'
  1538. '__SIZE_MAX__'
  1539. '__PTRDIFF_MAX__'
  1540. '__INTMAX_MAX__'
  1541. '__UINTMAX_MAX__'
  1542. '__SIG_ATOMIC_MAX__'
  1543. '__INT8_MAX__'
  1544. '__INT16_MAX__'
  1545. '__INT32_MAX__'
  1546. '__INT64_MAX__'
  1547. '__UINT8_MAX__'
  1548. '__UINT16_MAX__'
  1549. '__UINT32_MAX__'
  1550. '__UINT64_MAX__'
  1551. '__INT_LEAST8_MAX__'
  1552. '__INT_LEAST16_MAX__'
  1553. '__INT_LEAST32_MAX__'
  1554. '__INT_LEAST64_MAX__'
  1555. '__UINT_LEAST8_MAX__'
  1556. '__UINT_LEAST16_MAX__'
  1557. '__UINT_LEAST32_MAX__'
  1558. '__UINT_LEAST64_MAX__'
  1559. '__INT_FAST8_MAX__'
  1560. '__INT_FAST16_MAX__'
  1561. '__INT_FAST32_MAX__'
  1562. '__INT_FAST64_MAX__'
  1563. '__UINT_FAST8_MAX__'
  1564. '__UINT_FAST16_MAX__'
  1565. '__UINT_FAST32_MAX__'
  1566. '__UINT_FAST64_MAX__'
  1567. '__INTPTR_MAX__'
  1568. '__UINTPTR_MAX__'
  1569. '__WCHAR_MIN__'
  1570. '__WINT_MIN__'
  1571. '__SIG_ATOMIC_MIN__'
  1572. Defined to the maximum value of the 'signed char', 'wchar_t',
  1573. 'signed short', 'signed int', 'signed long', 'signed long long',
  1574. 'wint_t', 'size_t', 'ptrdiff_t', 'intmax_t', 'uintmax_t',
  1575. 'sig_atomic_t', 'int8_t', 'int16_t', 'int32_t', 'int64_t',
  1576. 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', 'int_least8_t',
  1577. 'int_least16_t', 'int_least32_t', 'int_least64_t', 'uint_least8_t',
  1578. 'uint_least16_t', 'uint_least32_t', 'uint_least64_t',
  1579. 'int_fast8_t', 'int_fast16_t', 'int_fast32_t', 'int_fast64_t',
  1580. 'uint_fast8_t', 'uint_fast16_t', 'uint_fast32_t', 'uint_fast64_t',
  1581. 'intptr_t', and 'uintptr_t' types and to the minimum value of the
  1582. 'wchar_t', 'wint_t', and 'sig_atomic_t' types respectively. They
  1583. exist to make the standard header given numerical limits work
  1584. correctly. You should not use these macros directly; instead,
  1585. include the appropriate headers. Some of these macros may not be
  1586. defined on particular systems if GCC does not provide a 'stdint.h'
  1587. header on those systems.
  1588. '__INT8_C'
  1589. '__INT16_C'
  1590. '__INT32_C'
  1591. '__INT64_C'
  1592. '__UINT8_C'
  1593. '__UINT16_C'
  1594. '__UINT32_C'
  1595. '__UINT64_C'
  1596. '__INTMAX_C'
  1597. '__UINTMAX_C'
  1598. Defined to implementations of the standard 'stdint.h' macros with
  1599. the same names without the leading '__'. They exist the make the
  1600. implementation of that header work correctly. You should not use
  1601. these macros directly; instead, include the appropriate headers.
  1602. Some of these macros may not be defined on particular systems if
  1603. GCC does not provide a 'stdint.h' header on those systems.
  1604. '__SCHAR_WIDTH__'
  1605. '__SHRT_WIDTH__'
  1606. '__INT_WIDTH__'
  1607. '__LONG_WIDTH__'
  1608. '__LONG_LONG_WIDTH__'
  1609. '__PTRDIFF_WIDTH__'
  1610. '__SIG_ATOMIC_WIDTH__'
  1611. '__SIZE_WIDTH__'
  1612. '__WCHAR_WIDTH__'
  1613. '__WINT_WIDTH__'
  1614. '__INT_LEAST8_WIDTH__'
  1615. '__INT_LEAST16_WIDTH__'
  1616. '__INT_LEAST32_WIDTH__'
  1617. '__INT_LEAST64_WIDTH__'
  1618. '__INT_FAST8_WIDTH__'
  1619. '__INT_FAST16_WIDTH__'
  1620. '__INT_FAST32_WIDTH__'
  1621. '__INT_FAST64_WIDTH__'
  1622. '__INTPTR_WIDTH__'
  1623. '__INTMAX_WIDTH__'
  1624. Defined to the bit widths of the corresponding types. They exist
  1625. to make the implementations of 'limits.h' and 'stdint.h' behave
  1626. correctly. You should not use these macros directly; instead,
  1627. include the appropriate headers. Some of these macros may not be
  1628. defined on particular systems if GCC does not provide a 'stdint.h'
  1629. header on those systems.
  1630. '__SIZEOF_INT__'
  1631. '__SIZEOF_LONG__'
  1632. '__SIZEOF_LONG_LONG__'
  1633. '__SIZEOF_SHORT__'
  1634. '__SIZEOF_POINTER__'
  1635. '__SIZEOF_FLOAT__'
  1636. '__SIZEOF_DOUBLE__'
  1637. '__SIZEOF_LONG_DOUBLE__'
  1638. '__SIZEOF_SIZE_T__'
  1639. '__SIZEOF_WCHAR_T__'
  1640. '__SIZEOF_WINT_T__'
  1641. '__SIZEOF_PTRDIFF_T__'
  1642. Defined to the number of bytes of the C standard data types: 'int',
  1643. 'long', 'long long', 'short', 'void *', 'float', 'double', 'long
  1644. double', 'size_t', 'wchar_t', 'wint_t' and 'ptrdiff_t'.
  1645. '__BYTE_ORDER__'
  1646. '__ORDER_LITTLE_ENDIAN__'
  1647. '__ORDER_BIG_ENDIAN__'
  1648. '__ORDER_PDP_ENDIAN__'
  1649. '__BYTE_ORDER__' is defined to one of the values
  1650. '__ORDER_LITTLE_ENDIAN__', '__ORDER_BIG_ENDIAN__', or
  1651. '__ORDER_PDP_ENDIAN__' to reflect the layout of multi-byte and
  1652. multi-word quantities in memory. If '__BYTE_ORDER__' is equal to
  1653. '__ORDER_LITTLE_ENDIAN__' or '__ORDER_BIG_ENDIAN__', then
  1654. multi-byte and multi-word quantities are laid out identically: the
  1655. byte (word) at the lowest address is the least significant or most
  1656. significant byte (word) of the quantity, respectively. If
  1657. '__BYTE_ORDER__' is equal to '__ORDER_PDP_ENDIAN__', then bytes in
  1658. 16-bit words are laid out in a little-endian fashion, whereas the
  1659. 16-bit subwords of a 32-bit quantity are laid out in big-endian
  1660. fashion.
  1661. You should use these macros for testing like this:
  1662. /* Test for a little-endian machine */
  1663. #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  1664. '__FLOAT_WORD_ORDER__'
  1665. '__FLOAT_WORD_ORDER__' is defined to one of the values
  1666. '__ORDER_LITTLE_ENDIAN__' or '__ORDER_BIG_ENDIAN__' to reflect the
  1667. layout of the words of multi-word floating-point quantities.
  1668. '__DEPRECATED'
  1669. This macro is defined, with value 1, when compiling a C++ source
  1670. file with warnings about deprecated constructs enabled. These
  1671. warnings are enabled by default, but can be disabled with
  1672. '-Wno-deprecated'.
  1673. '__EXCEPTIONS'
  1674. This macro is defined, with value 1, when compiling a C++ source
  1675. file with exceptions enabled. If '-fno-exceptions' is used when
  1676. compiling the file, then this macro is not defined.
  1677. '__GXX_RTTI'
  1678. This macro is defined, with value 1, when compiling a C++ source
  1679. file with runtime type identification enabled. If '-fno-rtti' is
  1680. used when compiling the file, then this macro is not defined.
  1681. '__USING_SJLJ_EXCEPTIONS__'
  1682. This macro is defined, with value 1, if the compiler uses the old
  1683. mechanism based on 'setjmp' and 'longjmp' for exception handling.
  1684. '__GXX_EXPERIMENTAL_CXX0X__'
  1685. This macro is defined when compiling a C++ source file with the
  1686. option '-std=c++0x' or '-std=gnu++0x'. It indicates that some
  1687. features likely to be included in C++0x are available. Note that
  1688. these features are experimental, and may change or be removed in
  1689. future versions of GCC.
  1690. '__GXX_WEAK__'
  1691. This macro is defined when compiling a C++ source file. It has the
  1692. value 1 if the compiler will use weak symbols, COMDAT sections, or
  1693. other similar techniques to collapse symbols with "vague linkage"
  1694. that are defined in multiple translation units. If the compiler
  1695. will not collapse such symbols, this macro is defined with value 0.
  1696. In general, user code should not need to make use of this macro;
  1697. the purpose of this macro is to ease implementation of the C++
  1698. runtime library provided with G++.
  1699. '__NEXT_RUNTIME__'
  1700. This macro is defined, with value 1, if (and only if) the NeXT
  1701. runtime (as in '-fnext-runtime') is in use for Objective-C. If the
  1702. GNU runtime is used, this macro is not defined, so that you can use
  1703. this macro to determine which runtime (NeXT or GNU) is being used.
  1704. '__LP64__'
  1705. '_LP64'
  1706. These macros are defined, with value 1, if (and only if) the
  1707. compilation is for a target where 'long int' and pointer both use
  1708. 64-bits and 'int' uses 32-bit.
  1709. '__SSP__'
  1710. This macro is defined, with value 1, when '-fstack-protector' is in
  1711. use.
  1712. '__SSP_ALL__'
  1713. This macro is defined, with value 2, when '-fstack-protector-all'
  1714. is in use.
  1715. '__SSP_STRONG__'
  1716. This macro is defined, with value 3, when
  1717. '-fstack-protector-strong' is in use.
  1718. '__SSP_EXPLICIT__'
  1719. This macro is defined, with value 4, when
  1720. '-fstack-protector-explicit' is in use.
  1721. '__SANITIZE_ADDRESS__'
  1722. This macro is defined, with value 1, when '-fsanitize=address' or
  1723. '-fsanitize=kernel-address' are in use.
  1724. '__SANITIZE_THREAD__'
  1725. This macro is defined, with value 1, when '-fsanitize=thread' is in
  1726. use.
  1727. '__TIMESTAMP__'
  1728. This macro expands to a string constant that describes the date and
  1729. time of the last modification of the current source file. The
  1730. string constant contains abbreviated day of the week, month, day of
  1731. the month, time in hh:mm:ss form, year and looks like
  1732. '"Sun Sep 16 01:03:52 1973"'. If the day of the month is less than
  1733. 10, it is padded with a space on the left.
  1734. If GCC cannot determine the current date, it will emit a warning
  1735. message (once per compilation) and '__TIMESTAMP__' will expand to
  1736. '"??? ??? ?? ??:??:?? ????"'.
  1737. '__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1'
  1738. '__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2'
  1739. '__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4'
  1740. '__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8'
  1741. '__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16'
  1742. These macros are defined when the target processor supports atomic
  1743. compare and swap operations on operands 1, 2, 4, 8 or 16 bytes in
  1744. length, respectively.
  1745. '__HAVE_SPECULATION_SAFE_VALUE'
  1746. This macro is defined with the value 1 to show that this version of
  1747. GCC supports '__builtin_speculation_safe_value'.
  1748. '__GCC_HAVE_DWARF2_CFI_ASM'
  1749. This macro is defined when the compiler is emitting DWARF CFI
  1750. directives to the assembler. When this is defined, it is possible
  1751. to emit those same directives in inline assembly.
  1752. '__FP_FAST_FMA'
  1753. '__FP_FAST_FMAF'
  1754. '__FP_FAST_FMAL'
  1755. These macros are defined with value 1 if the backend supports the
  1756. 'fma', 'fmaf', and 'fmal' builtin functions, so that the include
  1757. file 'math.h' can define the macros 'FP_FAST_FMA', 'FP_FAST_FMAF',
  1758. and 'FP_FAST_FMAL' for compatibility with the 1999 C standard.
  1759. '__FP_FAST_FMAF16'
  1760. '__FP_FAST_FMAF32'
  1761. '__FP_FAST_FMAF64'
  1762. '__FP_FAST_FMAF128'
  1763. '__FP_FAST_FMAF32X'
  1764. '__FP_FAST_FMAF64X'
  1765. '__FP_FAST_FMAF128X'
  1766. These macros are defined with the value 1 if the backend supports
  1767. the 'fma' functions using the additional '_FloatN' and '_FloatNx'
  1768. types that are defined in ISO/IEC TS 18661-3:2015. The include
  1769. file 'math.h' can define the 'FP_FAST_FMAFN' and 'FP_FAST_FMAFNx'
  1770. macros if the user defined '__STDC_WANT_IEC_60559_TYPES_EXT__'
  1771. before including 'math.h'.
  1772. '__GCC_IEC_559'
  1773. This macro is defined to indicate the intended level of support for
  1774. IEEE 754 (IEC 60559) floating-point arithmetic. It expands to a
  1775. nonnegative integer value. If 0, it indicates that the combination
  1776. of the compiler configuration and the command-line options is not
  1777. intended to support IEEE 754 arithmetic for 'float' and 'double' as
  1778. defined in C99 and C11 Annex F (for example, that the standard
  1779. rounding modes and exceptions are not supported, or that
  1780. optimizations are enabled that conflict with IEEE 754 semantics).
  1781. If 1, it indicates that IEEE 754 arithmetic is intended to be
  1782. supported; this does not mean that all relevant language features
  1783. are supported by GCC. If 2 or more, it additionally indicates
  1784. support for IEEE 754-2008 (in particular, that the binary encodings
  1785. for quiet and signaling NaNs are as specified in IEEE 754-2008).
  1786. This macro does not indicate the default state of command-line
  1787. options that control optimizations that C99 and C11 permit to be
  1788. controlled by standard pragmas, where those standards do not
  1789. require a particular default state. It does not indicate whether
  1790. optimizations respect signaling NaN semantics (the macro for that
  1791. is '__SUPPORT_SNAN__'). It does not indicate support for decimal
  1792. floating point or the IEEE 754 binary16 and binary128 types.
  1793. '__GCC_IEC_559_COMPLEX'
  1794. This macro is defined to indicate the intended level of support for
  1795. IEEE 754 (IEC 60559) floating-point arithmetic for complex numbers,
  1796. as defined in C99 and C11 Annex G. It expands to a nonnegative
  1797. integer value. If 0, it indicates that the combination of the
  1798. compiler configuration and the command-line options is not intended
  1799. to support Annex G requirements (for example, because
  1800. '-fcx-limited-range' was used). If 1 or more, it indicates that it
  1801. is intended to support those requirements; this does not mean that
  1802. all relevant language features are supported by GCC.
  1803. '__NO_MATH_ERRNO__'
  1804. This macro is defined if '-fno-math-errno' is used, or enabled by
  1805. another option such as '-ffast-math' or by default.
  1806. 
  1807. File: cpp.info, Node: System-specific Predefined Macros, Next: C++ Named Operators, Prev: Common Predefined Macros, Up: Predefined Macros
  1808. 3.7.3 System-specific Predefined Macros
  1809. ---------------------------------------
  1810. The C preprocessor normally predefines several macros that indicate what
  1811. type of system and machine is in use. They are obviously different on
  1812. each target supported by GCC. This manual, being for all systems and
  1813. machines, cannot tell you what their names are, but you can use 'cpp
  1814. -dM' to see them all. *Note Invocation::. All system-specific
  1815. predefined macros expand to a constant value, so you can test them with
  1816. either '#ifdef' or '#if'.
  1817. The C standard requires that all system-specific macros be part of
  1818. the "reserved namespace". All names which begin with two underscores,
  1819. or an underscore and a capital letter, are reserved for the compiler and
  1820. library to use as they wish. However, historically system-specific
  1821. macros have had names with no special prefix; for instance, it is common
  1822. to find 'unix' defined on Unix systems. For all such macros, GCC
  1823. provides a parallel macro with two underscores added at the beginning
  1824. and the end. If 'unix' is defined, '__unix__' will be defined too.
  1825. There will never be more than two underscores; the parallel of '_mips'
  1826. is '__mips__'.
  1827. When the '-ansi' option, or any '-std' option that requests strict
  1828. conformance, is given to the compiler, all the system-specific
  1829. predefined macros outside the reserved namespace are suppressed. The
  1830. parallel macros, inside the reserved namespace, remain defined.
  1831. We are slowly phasing out all predefined macros which are outside the
  1832. reserved namespace. You should never use them in new programs, and we
  1833. encourage you to correct older code to use the parallel macros whenever
  1834. you find it. We don't recommend you use the system-specific macros that
  1835. are in the reserved namespace, either. It is better in the long run to
  1836. check specifically for features you need, using a tool such as
  1837. 'autoconf'.
  1838. 
  1839. File: cpp.info, Node: C++ Named Operators, Prev: System-specific Predefined Macros, Up: Predefined Macros
  1840. 3.7.4 C++ Named Operators
  1841. -------------------------
  1842. In C++, there are eleven keywords which are simply alternate spellings
  1843. of operators normally written with punctuation. These keywords are
  1844. treated as such even in the preprocessor. They function as operators in
  1845. '#if', and they cannot be defined as macros or poisoned. In C, you can
  1846. request that those keywords take their C++ meaning by including
  1847. 'iso646.h'. That header defines each one as a normal object-like macro
  1848. expanding to the appropriate punctuator.
  1849. These are the named operators and their corresponding punctuators:
  1850. Named Operator Punctuator
  1851. 'and' '&&'
  1852. 'and_eq' '&='
  1853. 'bitand' '&'
  1854. 'bitor' '|'
  1855. 'compl' '~'
  1856. 'not' '!'
  1857. 'not_eq' '!='
  1858. 'or' '||'
  1859. 'or_eq' '|='
  1860. 'xor' '^'
  1861. 'xor_eq' '^='
  1862. 
  1863. File: cpp.info, Node: Undefining and Redefining Macros, Next: Directives Within Macro Arguments, Prev: Predefined Macros, Up: Macros
  1864. 3.8 Undefining and Redefining Macros
  1865. ====================================
  1866. If a macro ceases to be useful, it may be "undefined" with the '#undef'
  1867. directive. '#undef' takes a single argument, the name of the macro to
  1868. undefine. You use the bare macro name, even if the macro is
  1869. function-like. It is an error if anything appears on the line after the
  1870. macro name. '#undef' has no effect if the name is not a macro.
  1871. #define FOO 4
  1872. x = FOO; ==> x = 4;
  1873. #undef FOO
  1874. x = FOO; ==> x = FOO;
  1875. Once a macro has been undefined, that identifier may be "redefined"
  1876. as a macro by a subsequent '#define' directive. The new definition need
  1877. not have any resemblance to the old definition.
  1878. However, if an identifier which is currently a macro is redefined,
  1879. then the new definition must be "effectively the same" as the old one.
  1880. Two macro definitions are effectively the same if:
  1881. * Both are the same type of macro (object- or function-like).
  1882. * All the tokens of the replacement list are the same.
  1883. * If there are any parameters, they are the same.
  1884. * Whitespace appears in the same places in both. It need not be
  1885. exactly the same amount of whitespace, though. Remember that
  1886. comments count as whitespace.
  1887. These definitions are effectively the same:
  1888. #define FOUR (2 + 2)
  1889. #define FOUR (2 + 2)
  1890. #define FOUR (2 /* two */ + 2)
  1891. but these are not:
  1892. #define FOUR (2 + 2)
  1893. #define FOUR ( 2+2 )
  1894. #define FOUR (2 * 2)
  1895. #define FOUR(score,and,seven,years,ago) (2 + 2)
  1896. If a macro is redefined with a definition that is not effectively the
  1897. same as the old one, the preprocessor issues a warning and changes the
  1898. macro to use the new definition. If the new definition is effectively
  1899. the same, the redefinition is silently ignored. This allows, for
  1900. instance, two different headers to define a common macro. The
  1901. preprocessor will only complain if the definitions do not match.
  1902. 
  1903. File: cpp.info, Node: Directives Within Macro Arguments, Next: Macro Pitfalls, Prev: Undefining and Redefining Macros, Up: Macros
  1904. 3.9 Directives Within Macro Arguments
  1905. =====================================
  1906. Occasionally it is convenient to use preprocessor directives within the
  1907. arguments of a macro. The C and C++ standards declare that behavior in
  1908. these cases is undefined. GNU CPP processes arbitrary directives within
  1909. macro arguments in exactly the same way as it would have processed the
  1910. directive were the function-like macro invocation not present.
  1911. If, within a macro invocation, that macro is redefined, then the new
  1912. definition takes effect in time for argument pre-expansion, but the
  1913. original definition is still used for argument replacement. Here is a
  1914. pathological example:
  1915. #define f(x) x x
  1916. f (1
  1917. #undef f
  1918. #define f 2
  1919. f)
  1920. which expands to
  1921. 1 2 1 2
  1922. with the semantics described above.
  1923. 
  1924. File: cpp.info, Node: Macro Pitfalls, Prev: Directives Within Macro Arguments, Up: Macros
  1925. 3.10 Macro Pitfalls
  1926. ===================
  1927. In this section we describe some special rules that apply to macros and
  1928. macro expansion, and point out certain cases in which the rules have
  1929. counter-intuitive consequences that you must watch out for.
  1930. * Menu:
  1931. * Misnesting::
  1932. * Operator Precedence Problems::
  1933. * Swallowing the Semicolon::
  1934. * Duplication of Side Effects::
  1935. * Self-Referential Macros::
  1936. * Argument Prescan::
  1937. * Newlines in Arguments::
  1938. 
  1939. File: cpp.info, Node: Misnesting, Next: Operator Precedence Problems, Up: Macro Pitfalls
  1940. 3.10.1 Misnesting
  1941. -----------------
  1942. When a macro is called with arguments, the arguments are substituted
  1943. into the macro body and the result is checked, together with the rest of
  1944. the input file, for more macro calls. It is possible to piece together
  1945. a macro call coming partially from the macro body and partially from the
  1946. arguments. For example,
  1947. #define twice(x) (2*(x))
  1948. #define call_with_1(x) x(1)
  1949. call_with_1 (twice)
  1950. ==> twice(1)
  1951. ==> (2*(1))
  1952. Macro definitions do not have to have balanced parentheses. By
  1953. writing an unbalanced open parenthesis in a macro body, it is possible
  1954. to create a macro call that begins inside the macro body but ends
  1955. outside of it. For example,
  1956. #define strange(file) fprintf (file, "%s %d",
  1957. ...
  1958. strange(stderr) p, 35)
  1959. ==> fprintf (stderr, "%s %d", p, 35)
  1960. The ability to piece together a macro call can be useful, but the use
  1961. of unbalanced open parentheses in a macro body is just confusing, and
  1962. should be avoided.
  1963. 
  1964. File: cpp.info, Node: Operator Precedence Problems, Next: Swallowing the Semicolon, Prev: Misnesting, Up: Macro Pitfalls
  1965. 3.10.2 Operator Precedence Problems
  1966. -----------------------------------
  1967. You may have noticed that in most of the macro definition examples shown
  1968. above, each occurrence of a macro argument name had parentheses around
  1969. it. In addition, another pair of parentheses usually surround the
  1970. entire macro definition. Here is why it is best to write macros that
  1971. way.
  1972. Suppose you define a macro as follows,
  1973. #define ceil_div(x, y) (x + y - 1) / y
  1974. whose purpose is to divide, rounding up. (One use for this operation is
  1975. to compute how many 'int' objects are needed to hold a certain number of
  1976. 'char' objects.) Then suppose it is used as follows:
  1977. a = ceil_div (b & c, sizeof (int));
  1978. ==> a = (b & c + sizeof (int) - 1) / sizeof (int);
  1979. This does not do what is intended. The operator-precedence rules of C
  1980. make it equivalent to this:
  1981. a = (b & (c + sizeof (int) - 1)) / sizeof (int);
  1982. What we want is this:
  1983. a = ((b & c) + sizeof (int) - 1)) / sizeof (int);
  1984. Defining the macro as
  1985. #define ceil_div(x, y) ((x) + (y) - 1) / (y)
  1986. provides the desired result.
  1987. Unintended grouping can result in another way. Consider 'sizeof
  1988. ceil_div(1, 2)'. That has the appearance of a C expression that would
  1989. compute the size of the type of 'ceil_div (1, 2)', but in fact it means
  1990. something very different. Here is what it expands to:
  1991. sizeof ((1) + (2) - 1) / (2)
  1992. This would take the size of an integer and divide it by two. The
  1993. precedence rules have put the division outside the 'sizeof' when it was
  1994. intended to be inside.
  1995. Parentheses around the entire macro definition prevent such problems.
  1996. Here, then, is the recommended way to define 'ceil_div':
  1997. #define ceil_div(x, y) (((x) + (y) - 1) / (y))
  1998. 
  1999. File: cpp.info, Node: Swallowing the Semicolon, Next: Duplication of Side Effects, Prev: Operator Precedence Problems, Up: Macro Pitfalls
  2000. 3.10.3 Swallowing the Semicolon
  2001. -------------------------------
  2002. Often it is desirable to define a macro that expands into a compound
  2003. statement. Consider, for example, the following macro, that advances a
  2004. pointer (the argument 'p' says where to find it) across whitespace
  2005. characters:
  2006. #define SKIP_SPACES(p, limit) \
  2007. { char *lim = (limit); \
  2008. while (p < lim) { \
  2009. if (*p++ != ' ') { \
  2010. p--; break; }}}
  2011. Here backslash-newline is used to split the macro definition, which must
  2012. be a single logical line, so that it resembles the way such code would
  2013. be laid out if not part of a macro definition.
  2014. A call to this macro might be 'SKIP_SPACES (p, lim)'. Strictly
  2015. speaking, the call expands to a compound statement, which is a complete
  2016. statement with no need for a semicolon to end it. However, since it
  2017. looks like a function call, it minimizes confusion if you can use it
  2018. like a function call, writing a semicolon afterward, as in 'SKIP_SPACES
  2019. (p, lim);'
  2020. This can cause trouble before 'else' statements, because the
  2021. semicolon is actually a null statement. Suppose you write
  2022. if (*p != 0)
  2023. SKIP_SPACES (p, lim);
  2024. else ...
  2025. The presence of two statements--the compound statement and a null
  2026. statement--in between the 'if' condition and the 'else' makes invalid C
  2027. code.
  2028. The definition of the macro 'SKIP_SPACES' can be altered to solve
  2029. this problem, using a 'do ... while' statement. Here is how:
  2030. #define SKIP_SPACES(p, limit) \
  2031. do { char *lim = (limit); \
  2032. while (p < lim) { \
  2033. if (*p++ != ' ') { \
  2034. p--; break; }}} \
  2035. while (0)
  2036. Now 'SKIP_SPACES (p, lim);' expands into
  2037. do {...} while (0);
  2038. which is one statement. The loop executes exactly once; most compilers
  2039. generate no extra code for it.
  2040. 
  2041. File: cpp.info, Node: Duplication of Side Effects, Next: Self-Referential Macros, Prev: Swallowing the Semicolon, Up: Macro Pitfalls
  2042. 3.10.4 Duplication of Side Effects
  2043. ----------------------------------
  2044. Many C programs define a macro 'min', for "minimum", like this:
  2045. #define min(X, Y) ((X) < (Y) ? (X) : (Y))
  2046. When you use this macro with an argument containing a side effect, as
  2047. shown here,
  2048. next = min (x + y, foo (z));
  2049. it expands as follows:
  2050. next = ((x + y) < (foo (z)) ? (x + y) : (foo (z)));
  2051. where 'x + y' has been substituted for 'X' and 'foo (z)' for 'Y'.
  2052. The function 'foo' is used only once in the statement as it appears
  2053. in the program, but the expression 'foo (z)' has been substituted twice
  2054. into the macro expansion. As a result, 'foo' might be called two times
  2055. when the statement is executed. If it has side effects or if it takes a
  2056. long time to compute, the results might not be what you intended. We
  2057. say that 'min' is an "unsafe" macro.
  2058. The best solution to this problem is to define 'min' in a way that
  2059. computes the value of 'foo (z)' only once. The C language offers no
  2060. standard way to do this, but it can be done with GNU extensions as
  2061. follows:
  2062. #define min(X, Y) \
  2063. ({ typeof (X) x_ = (X); \
  2064. typeof (Y) y_ = (Y); \
  2065. (x_ < y_) ? x_ : y_; })
  2066. The '({ ... })' notation produces a compound statement that acts as
  2067. an expression. Its value is the value of its last statement. This
  2068. permits us to define local variables and assign each argument to one.
  2069. The local variables have underscores after their names to reduce the
  2070. risk of conflict with an identifier of wider scope (it is impossible to
  2071. avoid this entirely). Now each argument is evaluated exactly once.
  2072. If you do not wish to use GNU C extensions, the only solution is to
  2073. be careful when _using_ the macro 'min'. For example, you can calculate
  2074. the value of 'foo (z)', save it in a variable, and use that variable in
  2075. 'min':
  2076. #define min(X, Y) ((X) < (Y) ? (X) : (Y))
  2077. ...
  2078. {
  2079. int tem = foo (z);
  2080. next = min (x + y, tem);
  2081. }
  2082. (where we assume that 'foo' returns type 'int').
  2083. 
  2084. File: cpp.info, Node: Self-Referential Macros, Next: Argument Prescan, Prev: Duplication of Side Effects, Up: Macro Pitfalls
  2085. 3.10.5 Self-Referential Macros
  2086. ------------------------------
  2087. A "self-referential" macro is one whose name appears in its definition.
  2088. Recall that all macro definitions are rescanned for more macros to
  2089. replace. If the self-reference were considered a use of the macro, it
  2090. would produce an infinitely large expansion. To prevent this, the
  2091. self-reference is not considered a macro call. It is passed into the
  2092. preprocessor output unchanged. Consider an example:
  2093. #define foo (4 + foo)
  2094. where 'foo' is also a variable in your program.
  2095. Following the ordinary rules, each reference to 'foo' will expand
  2096. into '(4 + foo)'; then this will be rescanned and will expand into '(4 +
  2097. (4 + foo))'; and so on until the computer runs out of memory.
  2098. The self-reference rule cuts this process short after one step, at
  2099. '(4 + foo)'. Therefore, this macro definition has the possibly useful
  2100. effect of causing the program to add 4 to the value of 'foo' wherever
  2101. 'foo' is referred to.
  2102. In most cases, it is a bad idea to take advantage of this feature. A
  2103. person reading the program who sees that 'foo' is a variable will not
  2104. expect that it is a macro as well. The reader will come across the
  2105. identifier 'foo' in the program and think its value should be that of
  2106. the variable 'foo', whereas in fact the value is four greater.
  2107. One common, useful use of self-reference is to create a macro which
  2108. expands to itself. If you write
  2109. #define EPERM EPERM
  2110. then the macro 'EPERM' expands to 'EPERM'. Effectively, it is left
  2111. alone by the preprocessor whenever it's used in running text. You can
  2112. tell that it's a macro with '#ifdef'. You might do this if you want to
  2113. define numeric constants with an 'enum', but have '#ifdef' be true for
  2114. each constant.
  2115. If a macro 'x' expands to use a macro 'y', and the expansion of 'y'
  2116. refers to the macro 'x', that is an "indirect self-reference" of 'x'.
  2117. 'x' is not expanded in this case either. Thus, if we have
  2118. #define x (4 + y)
  2119. #define y (2 * x)
  2120. then 'x' and 'y' expand as follows:
  2121. x ==> (4 + y)
  2122. ==> (4 + (2 * x))
  2123. y ==> (2 * x)
  2124. ==> (2 * (4 + y))
  2125. Each macro is expanded when it appears in the definition of the other
  2126. macro, but not when it indirectly appears in its own definition.
  2127. 
  2128. File: cpp.info, Node: Argument Prescan, Next: Newlines in Arguments, Prev: Self-Referential Macros, Up: Macro Pitfalls
  2129. 3.10.6 Argument Prescan
  2130. -----------------------
  2131. Macro arguments are completely macro-expanded before they are
  2132. substituted into a macro body, unless they are stringized or pasted with
  2133. other tokens. After substitution, the entire macro body, including the
  2134. substituted arguments, is scanned again for macros to be expanded. The
  2135. result is that the arguments are scanned _twice_ to expand macro calls
  2136. in them.
  2137. Most of the time, this has no effect. If the argument contained any
  2138. macro calls, they are expanded during the first scan. The result
  2139. therefore contains no macro calls, so the second scan does not change
  2140. it. If the argument were substituted as given, with no prescan, the
  2141. single remaining scan would find the same macro calls and produce the
  2142. same results.
  2143. You might expect the double scan to change the results when a
  2144. self-referential macro is used in an argument of another macro (*note
  2145. Self-Referential Macros::): the self-referential macro would be expanded
  2146. once in the first scan, and a second time in the second scan. However,
  2147. this is not what happens. The self-references that do not expand in the
  2148. first scan are marked so that they will not expand in the second scan
  2149. either.
  2150. You might wonder, "Why mention the prescan, if it makes no
  2151. difference? And why not skip it and make the preprocessor faster?" The
  2152. answer is that the prescan does make a difference in three special
  2153. cases:
  2154. * Nested calls to a macro.
  2155. We say that "nested" calls to a macro occur when a macro's argument
  2156. contains a call to that very macro. For example, if 'f' is a macro
  2157. that expects one argument, 'f (f (1))' is a nested pair of calls to
  2158. 'f'. The desired expansion is made by expanding 'f (1)' and
  2159. substituting that into the definition of 'f'. The prescan causes
  2160. the expected result to happen. Without the prescan, 'f (1)' itself
  2161. would be substituted as an argument, and the inner use of 'f' would
  2162. appear during the main scan as an indirect self-reference and would
  2163. not be expanded.
  2164. * Macros that call other macros that stringize or concatenate.
  2165. If an argument is stringized or concatenated, the prescan does not
  2166. occur. If you _want_ to expand a macro, then stringize or
  2167. concatenate its expansion, you can do that by causing one macro to
  2168. call another macro that does the stringizing or concatenation. For
  2169. instance, if you have
  2170. #define AFTERX(x) X_ ## x
  2171. #define XAFTERX(x) AFTERX(x)
  2172. #define TABLESIZE 1024
  2173. #define BUFSIZE TABLESIZE
  2174. then 'AFTERX(BUFSIZE)' expands to 'X_BUFSIZE', and
  2175. 'XAFTERX(BUFSIZE)' expands to 'X_1024'. (Not to 'X_TABLESIZE'.
  2176. Prescan always does a complete expansion.)
  2177. * Macros used in arguments, whose expansions contain unshielded
  2178. commas.
  2179. This can cause a macro expanded on the second scan to be called
  2180. with the wrong number of arguments. Here is an example:
  2181. #define foo a,b
  2182. #define bar(x) lose(x)
  2183. #define lose(x) (1 + (x))
  2184. We would like 'bar(foo)' to turn into '(1 + (foo))', which would
  2185. then turn into '(1 + (a,b))'. Instead, 'bar(foo)' expands into
  2186. 'lose(a,b)', and you get an error because 'lose' requires a single
  2187. argument. In this case, the problem is easily solved by the same
  2188. parentheses that ought to be used to prevent misnesting of
  2189. arithmetic operations:
  2190. #define foo (a,b)
  2191. or
  2192. #define bar(x) lose((x))
  2193. The extra pair of parentheses prevents the comma in 'foo''s
  2194. definition from being interpreted as an argument separator.
  2195. 
  2196. File: cpp.info, Node: Newlines in Arguments, Prev: Argument Prescan, Up: Macro Pitfalls
  2197. 3.10.7 Newlines in Arguments
  2198. ----------------------------
  2199. The invocation of a function-like macro can extend over many logical
  2200. lines. However, in the present implementation, the entire expansion
  2201. comes out on one line. Thus line numbers emitted by the compiler or
  2202. debugger refer to the line the invocation started on, which might be
  2203. different to the line containing the argument causing the problem.
  2204. Here is an example illustrating this:
  2205. #define ignore_second_arg(a,b,c) a; c
  2206. ignore_second_arg (foo (),
  2207. ignored (),
  2208. syntax error);
  2209. The syntax error triggered by the tokens 'syntax error' results in an
  2210. error message citing line three--the line of ignore_second_arg-- even
  2211. though the problematic code comes from line five.
  2212. We consider this a bug, and intend to fix it in the near future.
  2213. 
  2214. File: cpp.info, Node: Conditionals, Next: Diagnostics, Prev: Macros, Up: Top
  2215. 4 Conditionals
  2216. **************
  2217. A "conditional" is a directive that instructs the preprocessor to select
  2218. whether or not to include a chunk of code in the final token stream
  2219. passed to the compiler. Preprocessor conditionals can test arithmetic
  2220. expressions, or whether a name is defined as a macro, or both
  2221. simultaneously using the special 'defined' operator.
  2222. A conditional in the C preprocessor resembles in some ways an 'if'
  2223. statement in C, but it is important to understand the difference between
  2224. them. The condition in an 'if' statement is tested during the execution
  2225. of your program. Its purpose is to allow your program to behave
  2226. differently from run to run, depending on the data it is operating on.
  2227. The condition in a preprocessing conditional directive is tested when
  2228. your program is compiled. Its purpose is to allow different code to be
  2229. included in the program depending on the situation at the time of
  2230. compilation.
  2231. However, the distinction is becoming less clear. Modern compilers
  2232. often do test 'if' statements when a program is compiled, if their
  2233. conditions are known not to vary at run time, and eliminate code which
  2234. can never be executed. If you can count on your compiler to do this,
  2235. you may find that your program is more readable if you use 'if'
  2236. statements with constant conditions (perhaps determined by macros). Of
  2237. course, you can only use this to exclude code, not type definitions or
  2238. other preprocessing directives, and you can only do it if the code
  2239. remains syntactically valid when it is not to be used.
  2240. * Menu:
  2241. * Conditional Uses::
  2242. * Conditional Syntax::
  2243. * Deleted Code::
  2244. 
  2245. File: cpp.info, Node: Conditional Uses, Next: Conditional Syntax, Up: Conditionals
  2246. 4.1 Conditional Uses
  2247. ====================
  2248. There are three general reasons to use a conditional.
  2249. * A program may need to use different code depending on the machine
  2250. or operating system it is to run on. In some cases the code for
  2251. one operating system may be erroneous on another operating system;
  2252. for example, it might refer to data types or constants that do not
  2253. exist on the other system. When this happens, it is not enough to
  2254. avoid executing the invalid code. Its mere presence will cause the
  2255. compiler to reject the program. With a preprocessing conditional,
  2256. the offending code can be effectively excised from the program when
  2257. it is not valid.
  2258. * You may want to be able to compile the same source file into two
  2259. different programs. One version might make frequent time-consuming
  2260. consistency checks on its intermediate data, or print the values of
  2261. those data for debugging, and the other not.
  2262. * A conditional whose condition is always false is one way to exclude
  2263. code from the program but keep it as a sort of comment for future
  2264. reference.
  2265. Simple programs that do not need system-specific logic or complex
  2266. debugging hooks generally will not need to use preprocessing
  2267. conditionals.
  2268. 
  2269. File: cpp.info, Node: Conditional Syntax, Next: Deleted Code, Prev: Conditional Uses, Up: Conditionals
  2270. 4.2 Conditional Syntax
  2271. ======================
  2272. A conditional in the C preprocessor begins with a "conditional
  2273. directive": '#if', '#ifdef' or '#ifndef'.
  2274. * Menu:
  2275. * Ifdef::
  2276. * If::
  2277. * Defined::
  2278. * Else::
  2279. * Elif::
  2280. * __has_attribute::
  2281. * __has_cpp_attribute::
  2282. * __has_include::
  2283. 
  2284. File: cpp.info, Node: Ifdef, Next: If, Up: Conditional Syntax
  2285. 4.2.1 Ifdef
  2286. -----------
  2287. The simplest sort of conditional is
  2288. #ifdef MACRO
  2289. CONTROLLED TEXT
  2290. #endif /* MACRO */
  2291. This block is called a "conditional group". CONTROLLED TEXT will be
  2292. included in the output of the preprocessor if and only if MACRO is
  2293. defined. We say that the conditional "succeeds" if MACRO is defined,
  2294. "fails" if it is not.
  2295. The CONTROLLED TEXT inside of a conditional can include preprocessing
  2296. directives. They are executed only if the conditional succeeds. You
  2297. can nest conditional groups inside other conditional groups, but they
  2298. must be completely nested. In other words, '#endif' always matches the
  2299. nearest '#ifdef' (or '#ifndef', or '#if'). Also, you cannot start a
  2300. conditional group in one file and end it in another.
  2301. Even if a conditional fails, the CONTROLLED TEXT inside it is still
  2302. run through initial transformations and tokenization. Therefore, it
  2303. must all be lexically valid C. Normally the only way this matters is
  2304. that all comments and string literals inside a failing conditional group
  2305. must still be properly ended.
  2306. The comment following the '#endif' is not required, but it is a good
  2307. practice if there is a lot of CONTROLLED TEXT, because it helps people
  2308. match the '#endif' to the corresponding '#ifdef'. Older programs
  2309. sometimes put MACRO directly after the '#endif' without enclosing it in
  2310. a comment. This is invalid code according to the C standard. CPP
  2311. accepts it with a warning. It never affects which '#ifndef' the
  2312. '#endif' matches.
  2313. Sometimes you wish to use some code if a macro is _not_ defined. You
  2314. can do this by writing '#ifndef' instead of '#ifdef'. One common use of
  2315. '#ifndef' is to include code only the first time a header file is
  2316. included. *Note Once-Only Headers::.
  2317. Macro definitions can vary between compilations for several reasons.
  2318. Here are some samples.
  2319. * Some macros are predefined on each kind of machine (*note
  2320. System-specific Predefined Macros::). This allows you to provide
  2321. code specially tuned for a particular machine.
  2322. * System header files define more macros, associated with the
  2323. features they implement. You can test these macros with
  2324. conditionals to avoid using a system feature on a machine where it
  2325. is not implemented.
  2326. * Macros can be defined or undefined with the '-D' and '-U'
  2327. command-line options when you compile the program. You can arrange
  2328. to compile the same source file into two different programs by
  2329. choosing a macro name to specify which program you want, writing
  2330. conditionals to test whether or how this macro is defined, and then
  2331. controlling the state of the macro with command-line options,
  2332. perhaps set in the Makefile. *Note Invocation::.
  2333. * Your program might have a special header file (often called
  2334. 'config.h') that is adjusted when the program is compiled. It can
  2335. define or not define macros depending on the features of the system
  2336. and the desired capabilities of the program. The adjustment can be
  2337. automated by a tool such as 'autoconf', or done by hand.
  2338. 
  2339. File: cpp.info, Node: If, Next: Defined, Prev: Ifdef, Up: Conditional Syntax
  2340. 4.2.2 If
  2341. --------
  2342. The '#if' directive allows you to test the value of an arithmetic
  2343. expression, rather than the mere existence of one macro. Its syntax is
  2344. #if EXPRESSION
  2345. CONTROLLED TEXT
  2346. #endif /* EXPRESSION */
  2347. EXPRESSION is a C expression of integer type, subject to stringent
  2348. restrictions. It may contain
  2349. * Integer constants.
  2350. * Character constants, which are interpreted as they would be in
  2351. normal code.
  2352. * Arithmetic operators for addition, subtraction, multiplication,
  2353. division, bitwise operations, shifts, comparisons, and logical
  2354. operations ('&&' and '||'). The latter two obey the usual
  2355. short-circuiting rules of standard C.
  2356. * Macros. All macros in the expression are expanded before actual
  2357. computation of the expression's value begins.
  2358. * Uses of the 'defined' operator, which lets you check whether macros
  2359. are defined in the middle of an '#if'.
  2360. * Identifiers that are not macros, which are all considered to be the
  2361. number zero. This allows you to write '#if MACRO' instead of
  2362. '#ifdef MACRO', if you know that MACRO, when defined, will always
  2363. have a nonzero value. Function-like macros used without their
  2364. function call parentheses are also treated as zero.
  2365. In some contexts this shortcut is undesirable. The '-Wundef'
  2366. option causes GCC to warn whenever it encounters an identifier
  2367. which is not a macro in an '#if'.
  2368. The preprocessor does not know anything about types in the language.
  2369. Therefore, 'sizeof' operators are not recognized in '#if', and neither
  2370. are 'enum' constants. They will be taken as identifiers which are not
  2371. macros, and replaced by zero. In the case of 'sizeof', this is likely
  2372. to cause the expression to be invalid.
  2373. The preprocessor calculates the value of EXPRESSION. It carries out
  2374. all calculations in the widest integer type known to the compiler; on
  2375. most machines supported by GCC this is 64 bits. This is not the same
  2376. rule as the compiler uses to calculate the value of a constant
  2377. expression, and may give different results in some cases. If the value
  2378. comes out to be nonzero, the '#if' succeeds and the CONTROLLED TEXT is
  2379. included; otherwise it is skipped.
  2380. 
  2381. File: cpp.info, Node: Defined, Next: Else, Prev: If, Up: Conditional Syntax
  2382. 4.2.3 Defined
  2383. -------------
  2384. The special operator 'defined' is used in '#if' and '#elif' expressions
  2385. to test whether a certain name is defined as a macro. 'defined NAME'
  2386. and 'defined (NAME)' are both expressions whose value is 1 if NAME is
  2387. defined as a macro at the current point in the program, and 0 otherwise.
  2388. Thus, '#if defined MACRO' is precisely equivalent to '#ifdef MACRO'.
  2389. 'defined' is useful when you wish to test more than one macro for
  2390. existence at once. For example,
  2391. #if defined (__vax__) || defined (__ns16000__)
  2392. would succeed if either of the names '__vax__' or '__ns16000__' is
  2393. defined as a macro.
  2394. Conditionals written like this:
  2395. #if defined BUFSIZE && BUFSIZE >= 1024
  2396. can generally be simplified to just '#if BUFSIZE >= 1024', since if
  2397. 'BUFSIZE' is not defined, it will be interpreted as having the value
  2398. zero.
  2399. If the 'defined' operator appears as a result of a macro expansion,
  2400. the C standard says the behavior is undefined. GNU cpp treats it as a
  2401. genuine 'defined' operator and evaluates it normally. It will warn
  2402. wherever your code uses this feature if you use the command-line option
  2403. '-Wpedantic', since other compilers may handle it differently. The
  2404. warning is also enabled by '-Wextra', and can also be enabled
  2405. individually with '-Wexpansion-to-defined'.
  2406. 
  2407. File: cpp.info, Node: Else, Next: Elif, Prev: Defined, Up: Conditional Syntax
  2408. 4.2.4 Else
  2409. ----------
  2410. The '#else' directive can be added to a conditional to provide
  2411. alternative text to be used if the condition fails. This is what it
  2412. looks like:
  2413. #if EXPRESSION
  2414. TEXT-IF-TRUE
  2415. #else /* Not EXPRESSION */
  2416. TEXT-IF-FALSE
  2417. #endif /* Not EXPRESSION */
  2418. If EXPRESSION is nonzero, the TEXT-IF-TRUE is included and the
  2419. TEXT-IF-FALSE is skipped. If EXPRESSION is zero, the opposite happens.
  2420. You can use '#else' with '#ifdef' and '#ifndef', too.
  2421. 
  2422. File: cpp.info, Node: Elif, Next: __has_attribute, Prev: Else, Up: Conditional Syntax
  2423. 4.2.5 Elif
  2424. ----------
  2425. One common case of nested conditionals is used to check for more than
  2426. two possible alternatives. For example, you might have
  2427. #if X == 1
  2428. ...
  2429. #else /* X != 1 */
  2430. #if X == 2
  2431. ...
  2432. #else /* X != 2 */
  2433. ...
  2434. #endif /* X != 2 */
  2435. #endif /* X != 1 */
  2436. Another conditional directive, '#elif', allows this to be abbreviated
  2437. as follows:
  2438. #if X == 1
  2439. ...
  2440. #elif X == 2
  2441. ...
  2442. #else /* X != 2 and X != 1*/
  2443. ...
  2444. #endif /* X != 2 and X != 1*/
  2445. '#elif' stands for "else if". Like '#else', it goes in the middle of
  2446. a conditional group and subdivides it; it does not require a matching
  2447. '#endif' of its own. Like '#if', the '#elif' directive includes an
  2448. expression to be tested. The text following the '#elif' is processed
  2449. only if the original '#if'-condition failed and the '#elif' condition
  2450. succeeds.
  2451. More than one '#elif' can go in the same conditional group. Then the
  2452. text after each '#elif' is processed only if the '#elif' condition
  2453. succeeds after the original '#if' and all previous '#elif' directives
  2454. within it have failed.
  2455. '#else' is allowed after any number of '#elif' directives, but
  2456. '#elif' may not follow '#else'.
  2457. 
  2458. File: cpp.info, Node: __has_attribute, Next: __has_cpp_attribute, Prev: Elif, Up: Conditional Syntax
  2459. 4.2.6 '__has_attribute'
  2460. -----------------------
  2461. The special operator '__has_attribute (OPERAND)' may be used in '#if'
  2462. and '#elif' expressions to test whether the attribute referenced by its
  2463. OPERAND is recognized by GCC. Using the operator in other contexts is
  2464. not valid. In C code, OPERAND must be a valid identifier. In C++ code,
  2465. OPERAND may be optionally introduced by the 'ATTRIBUTE-SCOPE::' prefix.
  2466. The ATTRIBUTE-SCOPE prefix identifies the "namespace" within which the
  2467. attribute is recognized. The scope of GCC attributes is 'gnu' or
  2468. '__gnu__'. The '__has_attribute' operator by itself, without any
  2469. OPERAND or parentheses, acts as a predefined macro so that support for
  2470. it can be tested in portable code. Thus, the recommended use of the
  2471. operator is as follows:
  2472. #if defined __has_attribute
  2473. # if __has_attribute (nonnull)
  2474. # define ATTR_NONNULL __attribute__ ((nonnull))
  2475. # endif
  2476. #endif
  2477. The first '#if' test succeeds only when the operator is supported by
  2478. the version of GCC (or another compiler) being used. Only when that
  2479. test succeeds is it valid to use '__has_attribute' as a preprocessor
  2480. operator. As a result, combining the two tests into a single expression
  2481. as shown below would only be valid with a compiler that supports the
  2482. operator but not with others that don't.
  2483. #if defined __has_attribute && __has_attribute (nonnull) /* not portable */
  2484. ...
  2485. #endif
  2486. 
  2487. File: cpp.info, Node: __has_cpp_attribute, Next: __has_include, Prev: __has_attribute, Up: Conditional Syntax
  2488. 4.2.7 '__has_cpp_attribute'
  2489. ---------------------------
  2490. The special operator '__has_cpp_attribute (OPERAND)' may be used in
  2491. '#if' and '#elif' expressions in C++ code to test whether the attribute
  2492. referenced by its OPERAND is recognized by GCC. '__has_cpp_attribute
  2493. (OPERAND)' is equivalent to '__has_attribute (OPERAND)' except that when
  2494. OPERAND designates a supported standard attribute it evaluates to an
  2495. integer constant of the form 'YYYYMM' indicating the year and month when
  2496. the attribute was first introduced into the C++ standard. For
  2497. additional information including the dates of the introduction of
  2498. current standard attributes, see
  2499. SD-6: SG10 Feature Test Recommendations (https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations/).
  2500. 
  2501. File: cpp.info, Node: __has_include, Prev: __has_cpp_attribute, Up: Conditional Syntax
  2502. 4.2.8 '__has_include'
  2503. ---------------------
  2504. The special operator '__has_include (OPERAND)' may be used in '#if' and
  2505. '#elif' expressions to test whether the header referenced by its OPERAND
  2506. can be included using the '#include' directive. Using the operator in
  2507. other contexts is not valid. The OPERAND takes the same form as the
  2508. file in the '#include' directive (*note Include Syntax::) and evaluates
  2509. to a nonzero value if the header can be included and to zero otherwise.
  2510. Note that that the ability to include a header doesn't imply that the
  2511. header doesn't contain invalid constructs or '#error' directives that
  2512. would cause the preprocessor to fail.
  2513. The '__has_include' operator by itself, without any OPERAND or
  2514. parentheses, acts as a predefined macro so that support for it can be
  2515. tested in portable code. Thus, the recommended use of the operator is
  2516. as follows:
  2517. #if defined __has_include
  2518. # if __has_include (<stdatomic.h>)
  2519. # include <stdatomic.h>
  2520. # endif
  2521. #endif
  2522. The first '#if' test succeeds only when the operator is supported by
  2523. the version of GCC (or another compiler) being used. Only when that
  2524. test succeeds is it valid to use '__has_include' as a preprocessor
  2525. operator. As a result, combining the two tests into a single expression
  2526. as shown below would only be valid with a compiler that supports the
  2527. operator but not with others that don't.
  2528. #if defined __has_include && __has_include ("header.h") /* not portable */
  2529. ...
  2530. #endif
  2531. 
  2532. File: cpp.info, Node: Deleted Code, Prev: Conditional Syntax, Up: Conditionals
  2533. 4.3 Deleted Code
  2534. ================
  2535. If you replace or delete a part of the program but want to keep the old
  2536. code around for future reference, you often cannot simply comment it
  2537. out. Block comments do not nest, so the first comment inside the old
  2538. code will end the commenting-out. The probable result is a flood of
  2539. syntax errors.
  2540. One way to avoid this problem is to use an always-false conditional
  2541. instead. For instance, put '#if 0' before the deleted code and '#endif'
  2542. after it. This works even if the code being turned off contains
  2543. conditionals, but they must be entire conditionals (balanced '#if' and
  2544. '#endif').
  2545. Some people use '#ifdef notdef' instead. This is risky, because
  2546. 'notdef' might be accidentally defined as a macro, and then the
  2547. conditional would succeed. '#if 0' can be counted on to fail.
  2548. Do not use '#if 0' for comments which are not C code. Use a real
  2549. comment, instead. The interior of '#if 0' must consist of complete
  2550. tokens; in particular, single-quote characters must balance. Comments
  2551. often contain unbalanced single-quote characters (known in English as
  2552. apostrophes). These confuse '#if 0'. They don't confuse '/*'.
  2553. 
  2554. File: cpp.info, Node: Diagnostics, Next: Line Control, Prev: Conditionals, Up: Top
  2555. 5 Diagnostics
  2556. *************
  2557. The directive '#error' causes the preprocessor to report a fatal error.
  2558. The tokens forming the rest of the line following '#error' are used as
  2559. the error message.
  2560. You would use '#error' inside of a conditional that detects a
  2561. combination of parameters which you know the program does not properly
  2562. support. For example, if you know that the program will not run
  2563. properly on a VAX, you might write
  2564. #ifdef __vax__
  2565. #error "Won't work on VAXen. See comments at get_last_object."
  2566. #endif
  2567. If you have several configuration parameters that must be set up by
  2568. the installation in a consistent way, you can use conditionals to detect
  2569. an inconsistency and report it with '#error'. For example,
  2570. #if !defined(FOO) && defined(BAR)
  2571. #error "BAR requires FOO."
  2572. #endif
  2573. The directive '#warning' is like '#error', but causes the
  2574. preprocessor to issue a warning and continue preprocessing. The tokens
  2575. following '#warning' are used as the warning message.
  2576. You might use '#warning' in obsolete header files, with a message
  2577. directing the user to the header file which should be used instead.
  2578. Neither '#error' nor '#warning' macro-expands its argument. Internal
  2579. whitespace sequences are each replaced with a single space. The line
  2580. must consist of complete tokens. It is wisest to make the argument of
  2581. these directives be a single string constant; this avoids problems with
  2582. apostrophes and the like.
  2583. 
  2584. File: cpp.info, Node: Line Control, Next: Pragmas, Prev: Diagnostics, Up: Top
  2585. 6 Line Control
  2586. **************
  2587. The C preprocessor informs the C compiler of the location in your source
  2588. code where each token came from. Presently, this is just the file name
  2589. and line number. All the tokens resulting from macro expansion are
  2590. reported as having appeared on the line of the source file where the
  2591. outermost macro was used. We intend to be more accurate in the future.
  2592. If you write a program which generates source code, such as the
  2593. 'bison' parser generator, you may want to adjust the preprocessor's
  2594. notion of the current file name and line number by hand. Parts of the
  2595. output from 'bison' are generated from scratch, other parts come from a
  2596. standard parser file. The rest are copied verbatim from 'bison''s
  2597. input. You would like compiler error messages and symbolic debuggers to
  2598. be able to refer to 'bison''s input file.
  2599. 'bison' or any such program can arrange this by writing '#line'
  2600. directives into the output file. '#line' is a directive that specifies
  2601. the original line number and source file name for subsequent input in
  2602. the current preprocessor input file. '#line' has three variants:
  2603. '#line LINENUM'
  2604. LINENUM is a non-negative decimal integer constant. It specifies
  2605. the line number which should be reported for the following line of
  2606. input. Subsequent lines are counted from LINENUM.
  2607. '#line LINENUM FILENAME'
  2608. LINENUM is the same as for the first form, and has the same effect.
  2609. In addition, FILENAME is a string constant. The following line and
  2610. all subsequent lines are reported to come from the file it
  2611. specifies, until something else happens to change that. FILENAME
  2612. is interpreted according to the normal rules for a string constant:
  2613. backslash escapes are interpreted. This is different from
  2614. '#include'.
  2615. '#line ANYTHING ELSE'
  2616. ANYTHING ELSE is checked for macro calls, which are expanded. The
  2617. result should match one of the above two forms.
  2618. '#line' directives alter the results of the '__FILE__' and '__LINE__'
  2619. predefined macros from that point on. *Note Standard Predefined
  2620. Macros::. They do not have any effect on '#include''s idea of the
  2621. directory containing the current file.
  2622. 
  2623. File: cpp.info, Node: Pragmas, Next: Other Directives, Prev: Line Control, Up: Top
  2624. 7 Pragmas
  2625. *********
  2626. The '#pragma' directive is the method specified by the C standard for
  2627. providing additional information to the compiler, beyond what is
  2628. conveyed in the language itself. The forms of this directive (commonly
  2629. known as "pragmas") specified by C standard are prefixed with 'STDC'. A
  2630. C compiler is free to attach any meaning it likes to other pragmas.
  2631. Most GNU-defined, supported pragmas have been given a 'GCC' prefix.
  2632. C99 introduced the '_Pragma' operator. This feature addresses a
  2633. major problem with '#pragma': being a directive, it cannot be produced
  2634. as the result of macro expansion. '_Pragma' is an operator, much like
  2635. 'sizeof' or 'defined', and can be embedded in a macro.
  2636. Its syntax is '_Pragma (STRING-LITERAL)', where STRING-LITERAL can be
  2637. either a normal or wide-character string literal. It is destringized,
  2638. by replacing all '\\' with a single '\' and all '\"' with a '"'. The
  2639. result is then processed as if it had appeared as the right hand side of
  2640. a '#pragma' directive. For example,
  2641. _Pragma ("GCC dependency \"parse.y\"")
  2642. has the same effect as '#pragma GCC dependency "parse.y"'. The same
  2643. effect could be achieved using macros, for example
  2644. #define DO_PRAGMA(x) _Pragma (#x)
  2645. DO_PRAGMA (GCC dependency "parse.y")
  2646. The standard is unclear on where a '_Pragma' operator can appear.
  2647. The preprocessor does not accept it within a preprocessing conditional
  2648. directive like '#if'. To be safe, you are probably best keeping it out
  2649. of directives other than '#define', and putting it on a line of its own.
  2650. This manual documents the pragmas which are meaningful to the
  2651. preprocessor itself. Other pragmas are meaningful to the C or C++
  2652. compilers. They are documented in the GCC manual.
  2653. GCC plugins may provide their own pragmas.
  2654. '#pragma GCC dependency'
  2655. '#pragma GCC dependency' allows you to check the relative dates of
  2656. the current file and another file. If the other file is more
  2657. recent than the current file, a warning is issued. This is useful
  2658. if the current file is derived from the other file, and should be
  2659. regenerated. The other file is searched for using the normal
  2660. include search path. Optional trailing text can be used to give
  2661. more information in the warning message.
  2662. #pragma GCC dependency "parse.y"
  2663. #pragma GCC dependency "/usr/include/time.h" rerun fixincludes
  2664. '#pragma GCC poison'
  2665. Sometimes, there is an identifier that you want to remove
  2666. completely from your program, and make sure that it never creeps
  2667. back in. To enforce this, you can "poison" the identifier with
  2668. this pragma. '#pragma GCC poison' is followed by a list of
  2669. identifiers to poison. If any of those identifiers appears
  2670. anywhere in the source after the directive, it is a hard error.
  2671. For example,
  2672. #pragma GCC poison printf sprintf fprintf
  2673. sprintf(some_string, "hello");
  2674. will produce an error.
  2675. If a poisoned identifier appears as part of the expansion of a
  2676. macro which was defined before the identifier was poisoned, it will
  2677. _not_ cause an error. This lets you poison an identifier without
  2678. worrying about system headers defining macros that use it.
  2679. For example,
  2680. #define strrchr rindex
  2681. #pragma GCC poison rindex
  2682. strrchr(some_string, 'h');
  2683. will not produce an error.
  2684. '#pragma GCC system_header'
  2685. This pragma takes no arguments. It causes the rest of the code in
  2686. the current file to be treated as if it came from a system header.
  2687. *Note System Headers::.
  2688. '#pragma GCC warning'
  2689. '#pragma GCC error'
  2690. '#pragma GCC warning "message"' causes the preprocessor to issue a
  2691. warning diagnostic with the text 'message'. The message contained
  2692. in the pragma must be a single string literal. Similarly, '#pragma
  2693. GCC error "message"' issues an error message. Unlike the
  2694. '#warning' and '#error' directives, these pragmas can be embedded
  2695. in preprocessor macros using '_Pragma'.
  2696. '#pragma once'
  2697. If '#pragma once' is seen when scanning a header file, that file
  2698. will never be read again, no matter what. It is a less-portable
  2699. alternative to using '#ifndef' to guard the contents of header
  2700. files against multiple inclusions.
  2701. 
  2702. File: cpp.info, Node: Other Directives, Next: Preprocessor Output, Prev: Pragmas, Up: Top
  2703. 8 Other Directives
  2704. ******************
  2705. The '#ident' directive takes one argument, a string constant. On some
  2706. systems, that string constant is copied into a special segment of the
  2707. object file. On other systems, the directive is ignored. The '#sccs'
  2708. directive is a synonym for '#ident'.
  2709. These directives are not part of the C standard, but they are not
  2710. official GNU extensions either. What historical information we have
  2711. been able to find, suggests they originated with System V.
  2712. The "null directive" consists of a '#' followed by a newline, with
  2713. only whitespace (including comments) in between. A null directive is
  2714. understood as a preprocessing directive but has no effect on the
  2715. preprocessor output. The primary significance of the existence of the
  2716. null directive is that an input line consisting of just a '#' will
  2717. produce no output, rather than a line of output containing just a '#'.
  2718. Supposedly some old C programs contain such lines.
  2719. 
  2720. File: cpp.info, Node: Preprocessor Output, Next: Traditional Mode, Prev: Other Directives, Up: Top
  2721. 9 Preprocessor Output
  2722. *********************
  2723. When the C preprocessor is used with the C, C++, or Objective-C
  2724. compilers, it is integrated into the compiler and communicates a stream
  2725. of binary tokens directly to the compiler's parser. However, it can
  2726. also be used in the more conventional standalone mode, where it produces
  2727. textual output.
  2728. The output from the C preprocessor looks much like the input, except
  2729. that all preprocessing directive lines have been replaced with blank
  2730. lines and all comments with spaces. Long runs of blank lines are
  2731. discarded.
  2732. The ISO standard specifies that it is implementation defined whether
  2733. a preprocessor preserves whitespace between tokens, or replaces it with
  2734. e.g. a single space. In GNU CPP, whitespace between tokens is collapsed
  2735. to become a single space, with the exception that the first token on a
  2736. non-directive line is preceded with sufficient spaces that it appears in
  2737. the same column in the preprocessed output that it appeared in the
  2738. original source file. This is so the output is easy to read. CPP does
  2739. not insert any whitespace where there was none in the original source,
  2740. except where necessary to prevent an accidental token paste.
  2741. Source file name and line number information is conveyed by lines of
  2742. the form
  2743. # LINENUM FILENAME FLAGS
  2744. These are called "linemarkers". They are inserted as needed into the
  2745. output (but never within a string or character constant). They mean
  2746. that the following line originated in file FILENAME at line LINENUM.
  2747. FILENAME will never contain any non-printing characters; they are
  2748. replaced with octal escape sequences.
  2749. After the file name comes zero or more flags, which are '1', '2',
  2750. '3', or '4'. If there are multiple flags, spaces separate them. Here
  2751. is what the flags mean:
  2752. '1'
  2753. This indicates the start of a new file.
  2754. '2'
  2755. This indicates returning to a file (after having included another
  2756. file).
  2757. '3'
  2758. This indicates that the following text comes from a system header
  2759. file, so certain warnings should be suppressed.
  2760. '4'
  2761. This indicates that the following text should be treated as being
  2762. wrapped in an implicit 'extern "C"' block.
  2763. As an extension, the preprocessor accepts linemarkers in
  2764. non-assembler input files. They are treated like the corresponding
  2765. '#line' directive, (*note Line Control::), except that trailing flags
  2766. are permitted, and are interpreted with the meanings described above.
  2767. If multiple flags are given, they must be in ascending order.
  2768. Some directives may be duplicated in the output of the preprocessor.
  2769. These are '#ident' (always), '#pragma' (only if the preprocessor does
  2770. not handle the pragma itself), and '#define' and '#undef' (with certain
  2771. debugging options). If this happens, the '#' of the directive will
  2772. always be in the first column, and there will be no space between the
  2773. '#' and the directive name. If macro expansion happens to generate
  2774. tokens which might be mistaken for a duplicated directive, a space will
  2775. be inserted between the '#' and the directive name.
  2776. 
  2777. File: cpp.info, Node: Traditional Mode, Next: Implementation Details, Prev: Preprocessor Output, Up: Top
  2778. 10 Traditional Mode
  2779. *******************
  2780. Traditional (pre-standard) C preprocessing is rather different from the
  2781. preprocessing specified by the standard. When the preprocessor is
  2782. invoked with the '-traditional-cpp' option, it attempts to emulate a
  2783. traditional preprocessor.
  2784. This mode is not useful for compiling C code with GCC, but is
  2785. intended for use with non-C preprocessing applications. Thus
  2786. traditional mode semantics are supported only when invoking the
  2787. preprocessor explicitly, and not in the compiler front ends.
  2788. The implementation does not correspond precisely to the behavior of
  2789. early pre-standard versions of GCC, nor to any true traditional
  2790. preprocessor. After all, inconsistencies among traditional
  2791. implementations were a major motivation for C standardization. However,
  2792. we intend that it should be compatible with true traditional
  2793. preprocessors in all ways that actually matter.
  2794. * Menu:
  2795. * Traditional lexical analysis::
  2796. * Traditional macros::
  2797. * Traditional miscellany::
  2798. * Traditional warnings::
  2799. 
  2800. File: cpp.info, Node: Traditional lexical analysis, Next: Traditional macros, Up: Traditional Mode
  2801. 10.1 Traditional lexical analysis
  2802. =================================
  2803. The traditional preprocessor does not decompose its input into tokens
  2804. the same way a standards-conforming preprocessor does. The input is
  2805. simply treated as a stream of text with minimal internal form.
  2806. This implementation does not treat trigraphs (*note trigraphs::)
  2807. specially since they were an invention of the standards committee. It
  2808. handles arbitrarily-positioned escaped newlines properly and splices the
  2809. lines as you would expect; many traditional preprocessors did not do
  2810. this.
  2811. The form of horizontal whitespace in the input file is preserved in
  2812. the output. In particular, hard tabs remain hard tabs. This can be
  2813. useful if, for example, you are preprocessing a Makefile.
  2814. Traditional CPP only recognizes C-style block comments, and treats
  2815. the '/*' sequence as introducing a comment only if it lies outside
  2816. quoted text. Quoted text is introduced by the usual single and double
  2817. quotes, and also by an initial '<' in a '#include' directive.
  2818. Traditionally, comments are completely removed and are not replaced
  2819. with a space. Since a traditional compiler does its own tokenization of
  2820. the output of the preprocessor, this means that comments can effectively
  2821. be used as token paste operators. However, comments behave like
  2822. separators for text handled by the preprocessor itself, since it doesn't
  2823. re-lex its input. For example, in
  2824. #if foo/**/bar
  2825. 'foo' and 'bar' are distinct identifiers and expanded separately if they
  2826. happen to be macros. In other words, this directive is equivalent to
  2827. #if foo bar
  2828. rather than
  2829. #if foobar
  2830. Generally speaking, in traditional mode an opening quote need not
  2831. have a matching closing quote. In particular, a macro may be defined
  2832. with replacement text that contains an unmatched quote. Of course, if
  2833. you attempt to compile preprocessed output containing an unmatched quote
  2834. you will get a syntax error.
  2835. However, all preprocessing directives other than '#define' require
  2836. matching quotes. For example:
  2837. #define m This macro's fine and has an unmatched quote
  2838. "/* This is not a comment. */
  2839. /* This is a comment. The following #include directive
  2840. is ill-formed. */
  2841. #include <stdio.h
  2842. Just as for the ISO preprocessor, what would be a closing quote can
  2843. be escaped with a backslash to prevent the quoted text from closing.
  2844. 
  2845. File: cpp.info, Node: Traditional macros, Next: Traditional miscellany, Prev: Traditional lexical analysis, Up: Traditional Mode
  2846. 10.2 Traditional macros
  2847. =======================
  2848. The major difference between traditional and ISO macros is that the
  2849. former expand to text rather than to a token sequence. CPP removes all
  2850. leading and trailing horizontal whitespace from a macro's replacement
  2851. text before storing it, but preserves the form of internal whitespace.
  2852. One consequence is that it is legitimate for the replacement text to
  2853. contain an unmatched quote (*note Traditional lexical analysis::). An
  2854. unclosed string or character constant continues into the text following
  2855. the macro call. Similarly, the text at the end of a macro's expansion
  2856. can run together with the text after the macro invocation to produce a
  2857. single token.
  2858. Normally comments are removed from the replacement text after the
  2859. macro is expanded, but if the '-CC' option is passed on the command-line
  2860. comments are preserved. (In fact, the current implementation removes
  2861. comments even before saving the macro replacement text, but it careful
  2862. to do it in such a way that the observed effect is identical even in the
  2863. function-like macro case.)
  2864. The ISO stringizing operator '#' and token paste operator '##' have
  2865. no special meaning. As explained later, an effect similar to these
  2866. operators can be obtained in a different way. Macro names that are
  2867. embedded in quotes, either from the main file or after macro
  2868. replacement, do not expand.
  2869. CPP replaces an unquoted object-like macro name with its replacement
  2870. text, and then rescans it for further macros to replace. Unlike
  2871. standard macro expansion, traditional macro expansion has no provision
  2872. to prevent recursion. If an object-like macro appears unquoted in its
  2873. replacement text, it will be replaced again during the rescan pass, and
  2874. so on _ad infinitum_. GCC detects when it is expanding recursive
  2875. macros, emits an error message, and continues after the offending macro
  2876. invocation.
  2877. #define PLUS +
  2878. #define INC(x) PLUS+x
  2879. INC(foo);
  2880. ==> ++foo;
  2881. Function-like macros are similar in form but quite different in
  2882. behavior to their ISO counterparts. Their arguments are contained
  2883. within parentheses, are comma-separated, and can cross physical lines.
  2884. Commas within nested parentheses are not treated as argument separators.
  2885. Similarly, a quote in an argument cannot be left unclosed; a following
  2886. comma or parenthesis that comes before the closing quote is treated like
  2887. any other character. There is no facility for handling variadic macros.
  2888. This implementation removes all comments from macro arguments, unless
  2889. the '-C' option is given. The form of all other horizontal whitespace
  2890. in arguments is preserved, including leading and trailing whitespace.
  2891. In particular
  2892. f( )
  2893. is treated as an invocation of the macro 'f' with a single argument
  2894. consisting of a single space. If you want to invoke a function-like
  2895. macro that takes no arguments, you must not leave any whitespace between
  2896. the parentheses.
  2897. If a macro argument crosses a new line, the new line is replaced with
  2898. a space when forming the argument. If the previous line contained an
  2899. unterminated quote, the following line inherits the quoted state.
  2900. Traditional preprocessors replace parameters in the replacement text
  2901. with their arguments regardless of whether the parameters are within
  2902. quotes or not. This provides a way to stringize arguments. For example
  2903. #define str(x) "x"
  2904. str(/* A comment */some text )
  2905. ==> "some text "
  2906. Note that the comment is removed, but that the trailing space is
  2907. preserved. Here is an example of using a comment to effect token
  2908. pasting.
  2909. #define suffix(x) foo_/**/x
  2910. suffix(bar)
  2911. ==> foo_bar
  2912. 
  2913. File: cpp.info, Node: Traditional miscellany, Next: Traditional warnings, Prev: Traditional macros, Up: Traditional Mode
  2914. 10.3 Traditional miscellany
  2915. ===========================
  2916. Here are some things to be aware of when using the traditional
  2917. preprocessor.
  2918. * Preprocessing directives are recognized only when their leading '#'
  2919. appears in the first column. There can be no whitespace between
  2920. the beginning of the line and the '#', but whitespace can follow
  2921. the '#'.
  2922. * A true traditional C preprocessor does not recognize '#error' or
  2923. '#pragma', and may not recognize '#elif'. CPP supports all the
  2924. directives in traditional mode that it supports in ISO mode,
  2925. including extensions, with the exception that the effects of
  2926. '#pragma GCC poison' are undefined.
  2927. * __STDC__ is not defined.
  2928. * If you use digraphs the behavior is undefined.
  2929. * If a line that looks like a directive appears within macro
  2930. arguments, the behavior is undefined.
  2931. 
  2932. File: cpp.info, Node: Traditional warnings, Prev: Traditional miscellany, Up: Traditional Mode
  2933. 10.4 Traditional warnings
  2934. =========================
  2935. You can request warnings about features that did not exist, or worked
  2936. differently, in traditional C with the '-Wtraditional' option. GCC does
  2937. not warn about features of ISO C which you must use when you are using a
  2938. conforming compiler, such as the '#' and '##' operators.
  2939. Presently '-Wtraditional' warns about:
  2940. * Macro parameters that appear within string literals in the macro
  2941. body. In traditional C macro replacement takes place within string
  2942. literals, but does not in ISO C.
  2943. * In traditional C, some preprocessor directives did not exist.
  2944. Traditional preprocessors would only consider a line to be a
  2945. directive if the '#' appeared in column 1 on the line. Therefore
  2946. '-Wtraditional' warns about directives that traditional C
  2947. understands but would ignore because the '#' does not appear as the
  2948. first character on the line. It also suggests you hide directives
  2949. like '#pragma' not understood by traditional C by indenting them.
  2950. Some traditional implementations would not recognize '#elif', so it
  2951. suggests avoiding it altogether.
  2952. * A function-like macro that appears without an argument list. In
  2953. some traditional preprocessors this was an error. In ISO C it
  2954. merely means that the macro is not expanded.
  2955. * The unary plus operator. This did not exist in traditional C.
  2956. * The 'U' and 'LL' integer constant suffixes, which were not
  2957. available in traditional C. (Traditional C does support the 'L'
  2958. suffix for simple long integer constants.) You are not warned
  2959. about uses of these suffixes in macros defined in system headers.
  2960. For instance, 'UINT_MAX' may well be defined as '4294967295U', but
  2961. you will not be warned if you use 'UINT_MAX'.
  2962. You can usually avoid the warning, and the related warning about
  2963. constants which are so large that they are unsigned, by writing the
  2964. integer constant in question in hexadecimal, with no U suffix.
  2965. Take care, though, because this gives the wrong result in exotic
  2966. cases.
  2967. 
  2968. File: cpp.info, Node: Implementation Details, Next: Invocation, Prev: Traditional Mode, Up: Top
  2969. 11 Implementation Details
  2970. *************************
  2971. Here we document details of how the preprocessor's implementation
  2972. affects its user-visible behavior. You should try to avoid undue
  2973. reliance on behavior described here, as it is possible that it will
  2974. change subtly in future implementations.
  2975. Also documented here are obsolete features still supported by CPP.
  2976. * Menu:
  2977. * Implementation-defined behavior::
  2978. * Implementation limits::
  2979. * Obsolete Features::
  2980. 
  2981. File: cpp.info, Node: Implementation-defined behavior, Next: Implementation limits, Up: Implementation Details
  2982. 11.1 Implementation-defined behavior
  2983. ====================================
  2984. This is how CPP behaves in all the cases which the C standard describes
  2985. as "implementation-defined". This term means that the implementation is
  2986. free to do what it likes, but must document its choice and stick to it.
  2987. * The mapping of physical source file multi-byte characters to the
  2988. execution character set.
  2989. The input character set can be specified using the
  2990. '-finput-charset' option, while the execution character set may be
  2991. controlled using the '-fexec-charset' and '-fwide-exec-charset'
  2992. options.
  2993. * Identifier characters.
  2994. The C and C++ standards allow identifiers to be composed of '_' and
  2995. the alphanumeric characters. C++ also allows universal character
  2996. names. C99 and later C standards permit both universal character
  2997. names and implementation-defined characters.
  2998. GCC allows the '$' character in identifiers as an extension for
  2999. most targets. This is true regardless of the 'std=' switch, since
  3000. this extension cannot conflict with standards-conforming programs.
  3001. When preprocessing assembler, however, dollars are not identifier
  3002. characters by default.
  3003. Currently the targets that by default do not permit '$' are AVR,
  3004. IP2K, MMIX, MIPS Irix 3, ARM aout, and PowerPC targets for the AIX
  3005. operating system.
  3006. You can override the default with '-fdollars-in-identifiers' or
  3007. 'fno-dollars-in-identifiers'. *Note fdollars-in-identifiers::.
  3008. * Non-empty sequences of whitespace characters.
  3009. In textual output, each whitespace sequence is collapsed to a
  3010. single space. For aesthetic reasons, the first token on each
  3011. non-directive line of output is preceded with sufficient spaces
  3012. that it appears in the same column as it did in the original source
  3013. file.
  3014. * The numeric value of character constants in preprocessor
  3015. expressions.
  3016. The preprocessor and compiler interpret character constants in the
  3017. same way; i.e. escape sequences such as '\a' are given the values
  3018. they would have on the target machine.
  3019. The compiler evaluates a multi-character character constant a
  3020. character at a time, shifting the previous value left by the number
  3021. of bits per target character, and then or-ing in the bit-pattern of
  3022. the new character truncated to the width of a target character.
  3023. The final bit-pattern is given type 'int', and is therefore signed,
  3024. regardless of whether single characters are signed or not. If
  3025. there are more characters in the constant than would fit in the
  3026. target 'int' the compiler issues a warning, and the excess leading
  3027. characters are ignored.
  3028. For example, ''ab'' for a target with an 8-bit 'char' would be
  3029. interpreted as
  3030. '(int) ((unsigned char) 'a' * 256 + (unsigned char) 'b')', and
  3031. ''\234a'' as
  3032. '(int) ((unsigned char) '\234' * 256 + (unsigned char) 'a')'.
  3033. * Source file inclusion.
  3034. For a discussion on how the preprocessor locates header files,
  3035. *note Include Operation::.
  3036. * Interpretation of the filename resulting from a macro-expanded
  3037. '#include' directive.
  3038. *Note Computed Includes::.
  3039. * Treatment of a '#pragma' directive that after macro-expansion
  3040. results in a standard pragma.
  3041. No macro expansion occurs on any '#pragma' directive line, so the
  3042. question does not arise.
  3043. Note that GCC does not yet implement any of the standard pragmas.
  3044. 
  3045. File: cpp.info, Node: Implementation limits, Next: Obsolete Features, Prev: Implementation-defined behavior, Up: Implementation Details
  3046. 11.2 Implementation limits
  3047. ==========================
  3048. CPP has a small number of internal limits. This section lists the
  3049. limits which the C standard requires to be no lower than some minimum,
  3050. and all the others known. It is intended that there should be as few
  3051. limits as possible. If you encounter an undocumented or inconvenient
  3052. limit, please report that as a bug. *Note Reporting Bugs: (gcc)Bugs.
  3053. Where we say something is limited "only by available memory", that
  3054. means that internal data structures impose no intrinsic limit, and space
  3055. is allocated with 'malloc' or equivalent. The actual limit will
  3056. therefore depend on many things, such as the size of other things
  3057. allocated by the compiler at the same time, the amount of memory
  3058. consumed by other processes on the same computer, etc.
  3059. * Nesting levels of '#include' files.
  3060. We impose an arbitrary limit of 200 levels, to avoid runaway
  3061. recursion. The standard requires at least 15 levels.
  3062. * Nesting levels of conditional inclusion.
  3063. The C standard mandates this be at least 63. CPP is limited only
  3064. by available memory.
  3065. * Levels of parenthesized expressions within a full expression.
  3066. The C standard requires this to be at least 63. In preprocessor
  3067. conditional expressions, it is limited only by available memory.
  3068. * Significant initial characters in an identifier or macro name.
  3069. The preprocessor treats all characters as significant. The C
  3070. standard requires only that the first 63 be significant.
  3071. * Number of macros simultaneously defined in a single translation
  3072. unit.
  3073. The standard requires at least 4095 be possible. CPP is limited
  3074. only by available memory.
  3075. * Number of parameters in a macro definition and arguments in a macro
  3076. call.
  3077. We allow 'USHRT_MAX', which is no smaller than 65,535. The minimum
  3078. required by the standard is 127.
  3079. * Number of characters on a logical source line.
  3080. The C standard requires a minimum of 4096 be permitted. CPP places
  3081. no limits on this, but you may get incorrect column numbers
  3082. reported in diagnostics for lines longer than 65,535 characters.
  3083. * Maximum size of a source file.
  3084. The standard does not specify any lower limit on the maximum size
  3085. of a source file. GNU cpp maps files into memory, so it is limited
  3086. by the available address space. This is generally at least two
  3087. gigabytes. Depending on the operating system, the size of physical
  3088. memory may or may not be a limitation.
  3089. 
  3090. File: cpp.info, Node: Obsolete Features, Prev: Implementation limits, Up: Implementation Details
  3091. 11.3 Obsolete Features
  3092. ======================
  3093. CPP has some features which are present mainly for compatibility with
  3094. older programs. We discourage their use in new code. In some cases, we
  3095. plan to remove the feature in a future version of GCC.
  3096. 11.3.1 Assertions
  3097. -----------------
  3098. "Assertions" are a deprecated alternative to macros in writing
  3099. conditionals to test what sort of computer or system the compiled
  3100. program will run on. Assertions are usually predefined, but you can
  3101. define them with preprocessing directives or command-line options.
  3102. Assertions were intended to provide a more systematic way to describe
  3103. the compiler's target system and we added them for compatibility with
  3104. existing compilers. In practice they are just as unpredictable as the
  3105. system-specific predefined macros. In addition, they are not part of
  3106. any standard, and only a few compilers support them. Therefore, the use
  3107. of assertions is *less* portable than the use of system-specific
  3108. predefined macros. We recommend you do not use them at all.
  3109. An assertion looks like this:
  3110. #PREDICATE (ANSWER)
  3111. PREDICATE must be a single identifier. ANSWER can be any sequence of
  3112. tokens; all characters are significant except for leading and trailing
  3113. whitespace, and differences in internal whitespace sequences are
  3114. ignored. (This is similar to the rules governing macro redefinition.)
  3115. Thus, '(x + y)' is different from '(x+y)' but equivalent to '( x + y )'.
  3116. Parentheses do not nest inside an answer.
  3117. To test an assertion, you write it in an '#if'. For example, this
  3118. conditional succeeds if either 'vax' or 'ns16000' has been asserted as
  3119. an answer for 'machine'.
  3120. #if #machine (vax) || #machine (ns16000)
  3121. You can test whether _any_ answer is asserted for a predicate by
  3122. omitting the answer in the conditional:
  3123. #if #machine
  3124. Assertions are made with the '#assert' directive. Its sole argument
  3125. is the assertion to make, without the leading '#' that identifies
  3126. assertions in conditionals.
  3127. #assert PREDICATE (ANSWER)
  3128. You may make several assertions with the same predicate and different
  3129. answers. Subsequent assertions do not override previous ones for the
  3130. same predicate. All the answers for any given predicate are
  3131. simultaneously true.
  3132. Assertions can be canceled with the '#unassert' directive. It has
  3133. the same syntax as '#assert'. In that form it cancels only the answer
  3134. which was specified on the '#unassert' line; other answers for that
  3135. predicate remain true. You can cancel an entire predicate by leaving
  3136. out the answer:
  3137. #unassert PREDICATE
  3138. In either form, if no such assertion has been made, '#unassert' has no
  3139. effect.
  3140. You can also make or cancel assertions using command-line options.
  3141. *Note Invocation::.
  3142. 
  3143. File: cpp.info, Node: Invocation, Next: Environment Variables, Prev: Implementation Details, Up: Top
  3144. 12 Invocation
  3145. *************
  3146. Most often when you use the C preprocessor you do not have to invoke it
  3147. explicitly: the C compiler does so automatically. However, the
  3148. preprocessor is sometimes useful on its own. You can invoke the
  3149. preprocessor either with the 'cpp' command, or via 'gcc -E'. In GCC,
  3150. the preprocessor is actually integrated with the compiler rather than a
  3151. separate program, and both of these commands invoke GCC and tell it to
  3152. stop after the preprocessing phase.
  3153. The 'cpp' options listed here are also accepted by 'gcc' and have the
  3154. same meaning. Likewise the 'cpp' command accepts all the usual 'gcc'
  3155. driver options, although those pertaining to compilation phases after
  3156. preprocessing are ignored.
  3157. Only options specific to preprocessing behavior are documented here.
  3158. Refer to the GCC manual for full documentation of other driver options.
  3159. The 'cpp' command expects two file names as arguments, INFILE and
  3160. OUTFILE. The preprocessor reads INFILE together with any other files it
  3161. specifies with '#include'. All the output generated by the combined
  3162. input files is written in OUTFILE.
  3163. Either INFILE or OUTFILE may be '-', which as INFILE means to read
  3164. from standard input and as OUTFILE means to write to standard output.
  3165. If either file is omitted, it means the same as if '-' had been
  3166. specified for that file. You can also use the '-o OUTFILE' option to
  3167. specify the output file.
  3168. Unless otherwise noted, or the option ends in '=', all options which
  3169. take an argument may have that argument appear either immediately after
  3170. the option, or with a space between option and argument: '-Ifoo' and '-I
  3171. foo' have the same effect.
  3172. Many options have multi-letter names; therefore multiple
  3173. single-letter options may _not_ be grouped: '-dM' is very different from
  3174. '-d -M'.
  3175. '-D NAME'
  3176. Predefine NAME as a macro, with definition '1'.
  3177. '-D NAME=DEFINITION'
  3178. The contents of DEFINITION are tokenized and processed as if they
  3179. appeared during translation phase three in a '#define' directive.
  3180. In particular, the definition is truncated by embedded newline
  3181. characters.
  3182. If you are invoking the preprocessor from a shell or shell-like
  3183. program you may need to use the shell's quoting syntax to protect
  3184. characters such as spaces that have a meaning in the shell syntax.
  3185. If you wish to define a function-like macro on the command line,
  3186. write its argument list with surrounding parentheses before the
  3187. equals sign (if any). Parentheses are meaningful to most shells,
  3188. so you should quote the option. With 'sh' and 'csh',
  3189. '-D'NAME(ARGS...)=DEFINITION'' works.
  3190. '-D' and '-U' options are processed in the order they are given on
  3191. the command line. All '-imacros FILE' and '-include FILE' options
  3192. are processed after all '-D' and '-U' options.
  3193. '-U NAME'
  3194. Cancel any previous definition of NAME, either built in or provided
  3195. with a '-D' option.
  3196. '-include FILE'
  3197. Process FILE as if '#include "file"' appeared as the first line of
  3198. the primary source file. However, the first directory searched for
  3199. FILE is the preprocessor's working directory _instead of_ the
  3200. directory containing the main source file. If not found there, it
  3201. is searched for in the remainder of the '#include "..."' search
  3202. chain as normal.
  3203. If multiple '-include' options are given, the files are included in
  3204. the order they appear on the command line.
  3205. '-imacros FILE'
  3206. Exactly like '-include', except that any output produced by
  3207. scanning FILE is thrown away. Macros it defines remain defined.
  3208. This allows you to acquire all the macros from a header without
  3209. also processing its declarations.
  3210. All files specified by '-imacros' are processed before all files
  3211. specified by '-include'.
  3212. '-undef'
  3213. Do not predefine any system-specific or GCC-specific macros. The
  3214. standard predefined macros remain defined. *Note Standard
  3215. Predefined Macros::.
  3216. '-pthread'
  3217. Define additional macros required for using the POSIX threads
  3218. library. You should use this option consistently for both
  3219. compilation and linking. This option is supported on GNU/Linux
  3220. targets, most other Unix derivatives, and also on x86 Cygwin and
  3221. MinGW targets.
  3222. '-M'
  3223. Instead of outputting the result of preprocessing, output a rule
  3224. suitable for 'make' describing the dependencies of the main source
  3225. file. The preprocessor outputs one 'make' rule containing the
  3226. object file name for that source file, a colon, and the names of
  3227. all the included files, including those coming from '-include' or
  3228. '-imacros' command-line options.
  3229. Unless specified explicitly (with '-MT' or '-MQ'), the object file
  3230. name consists of the name of the source file with any suffix
  3231. replaced with object file suffix and with any leading directory
  3232. parts removed. If there are many included files then the rule is
  3233. split into several lines using '\'-newline. The rule has no
  3234. commands.
  3235. This option does not suppress the preprocessor's debug output, such
  3236. as '-dM'. To avoid mixing such debug output with the dependency
  3237. rules you should explicitly specify the dependency output file with
  3238. '-MF', or use an environment variable like 'DEPENDENCIES_OUTPUT'
  3239. (*note Environment Variables::). Debug output is still sent to the
  3240. regular output stream as normal.
  3241. Passing '-M' to the driver implies '-E', and suppresses warnings
  3242. with an implicit '-w'.
  3243. '-MM'
  3244. Like '-M' but do not mention header files that are found in system
  3245. header directories, nor header files that are included, directly or
  3246. indirectly, from such a header.
  3247. This implies that the choice of angle brackets or double quotes in
  3248. an '#include' directive does not in itself determine whether that
  3249. header appears in '-MM' dependency output.
  3250. '-MF FILE'
  3251. When used with '-M' or '-MM', specifies a file to write the
  3252. dependencies to. If no '-MF' switch is given the preprocessor
  3253. sends the rules to the same place it would send preprocessed
  3254. output.
  3255. When used with the driver options '-MD' or '-MMD', '-MF' overrides
  3256. the default dependency output file.
  3257. If FILE is '-', then the dependencies are written to 'stdout'.
  3258. '-MG'
  3259. In conjunction with an option such as '-M' requesting dependency
  3260. generation, '-MG' assumes missing header files are generated files
  3261. and adds them to the dependency list without raising an error. The
  3262. dependency filename is taken directly from the '#include' directive
  3263. without prepending any path. '-MG' also suppresses preprocessed
  3264. output, as a missing header file renders this useless.
  3265. This feature is used in automatic updating of makefiles.
  3266. '-MP'
  3267. This option instructs CPP to add a phony target for each dependency
  3268. other than the main file, causing each to depend on nothing. These
  3269. dummy rules work around errors 'make' gives if you remove header
  3270. files without updating the 'Makefile' to match.
  3271. This is typical output:
  3272. test.o: test.c test.h
  3273. test.h:
  3274. '-MT TARGET'
  3275. Change the target of the rule emitted by dependency generation. By
  3276. default CPP takes the name of the main input file, deletes any
  3277. directory components and any file suffix such as '.c', and appends
  3278. the platform's usual object suffix. The result is the target.
  3279. An '-MT' option sets the target to be exactly the string you
  3280. specify. If you want multiple targets, you can specify them as a
  3281. single argument to '-MT', or use multiple '-MT' options.
  3282. For example, '-MT '$(objpfx)foo.o'' might give
  3283. $(objpfx)foo.o: foo.c
  3284. '-MQ TARGET'
  3285. Same as '-MT', but it quotes any characters which are special to
  3286. Make. '-MQ '$(objpfx)foo.o'' gives
  3287. $$(objpfx)foo.o: foo.c
  3288. The default target is automatically quoted, as if it were given
  3289. with '-MQ'.
  3290. '-MD'
  3291. '-MD' is equivalent to '-M -MF FILE', except that '-E' is not
  3292. implied. The driver determines FILE based on whether an '-o'
  3293. option is given. If it is, the driver uses its argument but with a
  3294. suffix of '.d', otherwise it takes the name of the input file,
  3295. removes any directory components and suffix, and applies a '.d'
  3296. suffix.
  3297. If '-MD' is used in conjunction with '-E', any '-o' switch is
  3298. understood to specify the dependency output file (*note -MF:
  3299. dashMF.), but if used without '-E', each '-o' is understood to
  3300. specify a target object file.
  3301. Since '-E' is not implied, '-MD' can be used to generate a
  3302. dependency output file as a side effect of the compilation process.
  3303. '-MMD'
  3304. Like '-MD' except mention only user header files, not system header
  3305. files.
  3306. '-fpreprocessed'
  3307. Indicate to the preprocessor that the input file has already been
  3308. preprocessed. This suppresses things like macro expansion,
  3309. trigraph conversion, escaped newline splicing, and processing of
  3310. most directives. The preprocessor still recognizes and removes
  3311. comments, so that you can pass a file preprocessed with '-C' to the
  3312. compiler without problems. In this mode the integrated
  3313. preprocessor is little more than a tokenizer for the front ends.
  3314. '-fpreprocessed' is implicit if the input file has one of the
  3315. extensions '.i', '.ii' or '.mi'. These are the extensions that GCC
  3316. uses for preprocessed files created by '-save-temps'.
  3317. '-fdirectives-only'
  3318. When preprocessing, handle directives, but do not expand macros.
  3319. The option's behavior depends on the '-E' and '-fpreprocessed'
  3320. options.
  3321. With '-E', preprocessing is limited to the handling of directives
  3322. such as '#define', '#ifdef', and '#error'. Other preprocessor
  3323. operations, such as macro expansion and trigraph conversion are not
  3324. performed. In addition, the '-dD' option is implicitly enabled.
  3325. With '-fpreprocessed', predefinition of command line and most
  3326. builtin macros is disabled. Macros such as '__LINE__', which are
  3327. contextually dependent, are handled normally. This enables
  3328. compilation of files previously preprocessed with '-E
  3329. -fdirectives-only'.
  3330. With both '-E' and '-fpreprocessed', the rules for '-fpreprocessed'
  3331. take precedence. This enables full preprocessing of files
  3332. previously preprocessed with '-E -fdirectives-only'.
  3333. '-fdollars-in-identifiers'
  3334. Accept '$' in identifiers. *Note Identifier characters::.
  3335. '-fextended-identifiers'
  3336. Accept universal character names in identifiers. This option is
  3337. enabled by default for C99 (and later C standard versions) and C++.
  3338. '-fno-canonical-system-headers'
  3339. When preprocessing, do not shorten system header paths with
  3340. canonicalization.
  3341. '-ftabstop=WIDTH'
  3342. Set the distance between tab stops. This helps the preprocessor
  3343. report correct column numbers in warnings or errors, even if tabs
  3344. appear on the line. If the value is less than 1 or greater than
  3345. 100, the option is ignored. The default is 8.
  3346. '-ftrack-macro-expansion[=LEVEL]'
  3347. Track locations of tokens across macro expansions. This allows the
  3348. compiler to emit diagnostic about the current macro expansion stack
  3349. when a compilation error occurs in a macro expansion. Using this
  3350. option makes the preprocessor and the compiler consume more memory.
  3351. The LEVEL parameter can be used to choose the level of precision of
  3352. token location tracking thus decreasing the memory consumption if
  3353. necessary. Value '0' of LEVEL de-activates this option. Value '1'
  3354. tracks tokens locations in a degraded mode for the sake of minimal
  3355. memory overhead. In this mode all tokens resulting from the
  3356. expansion of an argument of a function-like macro have the same
  3357. location. Value '2' tracks tokens locations completely. This
  3358. value is the most memory hungry. When this option is given no
  3359. argument, the default parameter value is '2'.
  3360. Note that '-ftrack-macro-expansion=2' is activated by default.
  3361. '-fmacro-prefix-map=OLD=NEW'
  3362. When preprocessing files residing in directory 'OLD', expand the
  3363. '__FILE__' and '__BASE_FILE__' macros as if the files resided in
  3364. directory 'NEW' instead. This can be used to change an absolute
  3365. path to a relative path by using '.' for NEW which can result in
  3366. more reproducible builds that are location independent. This
  3367. option also affects '__builtin_FILE()' during compilation. See
  3368. also '-ffile-prefix-map'.
  3369. '-fexec-charset=CHARSET'
  3370. Set the execution character set, used for string and character
  3371. constants. The default is UTF-8. CHARSET can be any encoding
  3372. supported by the system's 'iconv' library routine.
  3373. '-fwide-exec-charset=CHARSET'
  3374. Set the wide execution character set, used for wide string and
  3375. character constants. The default is UTF-32 or UTF-16, whichever
  3376. corresponds to the width of 'wchar_t'. As with '-fexec-charset',
  3377. CHARSET can be any encoding supported by the system's 'iconv'
  3378. library routine; however, you will have problems with encodings
  3379. that do not fit exactly in 'wchar_t'.
  3380. '-finput-charset=CHARSET'
  3381. Set the input character set, used for translation from the
  3382. character set of the input file to the source character set used by
  3383. GCC. If the locale does not specify, or GCC cannot get this
  3384. information from the locale, the default is UTF-8. This can be
  3385. overridden by either the locale or this command-line option.
  3386. Currently the command-line option takes precedence if there's a
  3387. conflict. CHARSET can be any encoding supported by the system's
  3388. 'iconv' library routine.
  3389. '-fworking-directory'
  3390. Enable generation of linemarkers in the preprocessor output that
  3391. let the compiler know the current working directory at the time of
  3392. preprocessing. When this option is enabled, the preprocessor
  3393. emits, after the initial linemarker, a second linemarker with the
  3394. current working directory followed by two slashes. GCC uses this
  3395. directory, when it's present in the preprocessed input, as the
  3396. directory emitted as the current working directory in some
  3397. debugging information formats. This option is implicitly enabled
  3398. if debugging information is enabled, but this can be inhibited with
  3399. the negated form '-fno-working-directory'. If the '-P' flag is
  3400. present in the command line, this option has no effect, since no
  3401. '#line' directives are emitted whatsoever.
  3402. '-A PREDICATE=ANSWER'
  3403. Make an assertion with the predicate PREDICATE and answer ANSWER.
  3404. This form is preferred to the older form '-A PREDICATE(ANSWER)',
  3405. which is still supported, because it does not use shell special
  3406. characters. *Note Obsolete Features::.
  3407. '-A -PREDICATE=ANSWER'
  3408. Cancel an assertion with the predicate PREDICATE and answer ANSWER.
  3409. '-C'
  3410. Do not discard comments. All comments are passed through to the
  3411. output file, except for comments in processed directives, which are
  3412. deleted along with the directive.
  3413. You should be prepared for side effects when using '-C'; it causes
  3414. the preprocessor to treat comments as tokens in their own right.
  3415. For example, comments appearing at the start of what would be a
  3416. directive line have the effect of turning that line into an
  3417. ordinary source line, since the first token on the line is no
  3418. longer a '#'.
  3419. '-CC'
  3420. Do not discard comments, including during macro expansion. This is
  3421. like '-C', except that comments contained within macros are also
  3422. passed through to the output file where the macro is expanded.
  3423. In addition to the side effects of the '-C' option, the '-CC'
  3424. option causes all C++-style comments inside a macro to be converted
  3425. to C-style comments. This is to prevent later use of that macro
  3426. from inadvertently commenting out the remainder of the source line.
  3427. The '-CC' option is generally used to support lint comments.
  3428. '-P'
  3429. Inhibit generation of linemarkers in the output from the
  3430. preprocessor. This might be useful when running the preprocessor
  3431. on something that is not C code, and will be sent to a program
  3432. which might be confused by the linemarkers. *Note Preprocessor
  3433. Output::.
  3434. '-traditional'
  3435. '-traditional-cpp'
  3436. Try to imitate the behavior of pre-standard C preprocessors, as
  3437. opposed to ISO C preprocessors. *Note Traditional Mode::.
  3438. Note that GCC does not otherwise attempt to emulate a pre-standard
  3439. C compiler, and these options are only supported with the '-E'
  3440. switch, or when invoking CPP explicitly.
  3441. '-trigraphs'
  3442. Support ISO C trigraphs. These are three-character sequences, all
  3443. starting with '??', that are defined by ISO C to stand for single
  3444. characters. For example, '??/' stands for '\', so ''??/n'' is a
  3445. character constant for a newline. *Note Initial processing::.
  3446. By default, GCC ignores trigraphs, but in standard-conforming modes
  3447. it converts them. See the '-std' and '-ansi' options.
  3448. '-remap'
  3449. Enable special code to work around file systems which only permit
  3450. very short file names, such as MS-DOS.
  3451. '-H'
  3452. Print the name of each header file used, in addition to other
  3453. normal activities. Each name is indented to show how deep in the
  3454. '#include' stack it is. Precompiled header files are also printed,
  3455. even if they are found to be invalid; an invalid precompiled header
  3456. file is printed with '...x' and a valid one with '...!' .
  3457. '-dLETTERS'
  3458. Says to make debugging dumps during compilation as specified by
  3459. LETTERS. The flags documented here are those relevant to the
  3460. preprocessor. Other LETTERS are interpreted by the compiler
  3461. proper, or reserved for future versions of GCC, and so are silently
  3462. ignored. If you specify LETTERS whose behavior conflicts, the
  3463. result is undefined.
  3464. '-dM'
  3465. Instead of the normal output, generate a list of '#define'
  3466. directives for all the macros defined during the execution of
  3467. the preprocessor, including predefined macros. This gives you
  3468. a way of finding out what is predefined in your version of the
  3469. preprocessor. Assuming you have no file 'foo.h', the command
  3470. touch foo.h; cpp -dM foo.h
  3471. shows all the predefined macros.
  3472. '-dD'
  3473. Like '-dM' except in two respects: it does _not_ include the
  3474. predefined macros, and it outputs _both_ the '#define'
  3475. directives and the result of preprocessing. Both kinds of
  3476. output go to the standard output file.
  3477. '-dN'
  3478. Like '-dD', but emit only the macro names, not their
  3479. expansions.
  3480. '-dI'
  3481. Output '#include' directives in addition to the result of
  3482. preprocessing.
  3483. '-dU'
  3484. Like '-dD' except that only macros that are expanded, or whose
  3485. definedness is tested in preprocessor directives, are output;
  3486. the output is delayed until the use or test of the macro; and
  3487. '#undef' directives are also output for macros tested but
  3488. undefined at the time.
  3489. '-fdebug-cpp'
  3490. This option is only useful for debugging GCC. When used from CPP or
  3491. with '-E', it dumps debugging information about location maps.
  3492. Every token in the output is preceded by the dump of the map its
  3493. location belongs to.
  3494. When used from GCC without '-E', this option has no effect.
  3495. '-I DIR'
  3496. '-iquote DIR'
  3497. '-isystem DIR'
  3498. '-idirafter DIR'
  3499. Add the directory DIR to the list of directories to be searched for
  3500. header files during preprocessing. *Note Search Path::. If DIR
  3501. begins with '=' or '$SYSROOT', then the '=' or '$SYSROOT' is
  3502. replaced by the sysroot prefix; see '--sysroot' and '-isysroot'.
  3503. Directories specified with '-iquote' apply only to the quote form
  3504. of the directive, '#include "FILE"'. Directories specified with
  3505. '-I', '-isystem', or '-idirafter' apply to lookup for both the
  3506. '#include "FILE"' and '#include <FILE>' directives.
  3507. You can specify any number or combination of these options on the
  3508. command line to search for header files in several directories.
  3509. The lookup order is as follows:
  3510. 1. For the quote form of the include directive, the directory of
  3511. the current file is searched first.
  3512. 2. For the quote form of the include directive, the directories
  3513. specified by '-iquote' options are searched in left-to-right
  3514. order, as they appear on the command line.
  3515. 3. Directories specified with '-I' options are scanned in
  3516. left-to-right order.
  3517. 4. Directories specified with '-isystem' options are scanned in
  3518. left-to-right order.
  3519. 5. Standard system directories are scanned.
  3520. 6. Directories specified with '-idirafter' options are scanned in
  3521. left-to-right order.
  3522. You can use '-I' to override a system header file, substituting
  3523. your own version, since these directories are searched before the
  3524. standard system header file directories. However, you should not
  3525. use this option to add directories that contain vendor-supplied
  3526. system header files; use '-isystem' for that.
  3527. The '-isystem' and '-idirafter' options also mark the directory as
  3528. a system directory, so that it gets the same special treatment that
  3529. is applied to the standard system directories. *Note System
  3530. Headers::.
  3531. If a standard system include directory, or a directory specified
  3532. with '-isystem', is also specified with '-I', the '-I' option is
  3533. ignored. The directory is still searched but as a system directory
  3534. at its normal position in the system include chain. This is to
  3535. ensure that GCC's procedure to fix buggy system headers and the
  3536. ordering for the '#include_next' directive are not inadvertently
  3537. changed. If you really need to change the search order for system
  3538. directories, use the '-nostdinc' and/or '-isystem' options. *Note
  3539. System Headers::.
  3540. '-I-'
  3541. Split the include path. This option has been deprecated. Please
  3542. use '-iquote' instead for '-I' directories before the '-I-' and
  3543. remove the '-I-' option.
  3544. Any directories specified with '-I' options before '-I-' are
  3545. searched only for headers requested with '#include "FILE"'; they
  3546. are not searched for '#include <FILE>'. If additional directories
  3547. are specified with '-I' options after the '-I-', those directories
  3548. are searched for all '#include' directives.
  3549. In addition, '-I-' inhibits the use of the directory of the current
  3550. file directory as the first search directory for '#include "FILE"'.
  3551. There is no way to override this effect of '-I-'. *Note Search
  3552. Path::.
  3553. '-iprefix PREFIX'
  3554. Specify PREFIX as the prefix for subsequent '-iwithprefix' options.
  3555. If the prefix represents a directory, you should include the final
  3556. '/'.
  3557. '-iwithprefix DIR'
  3558. '-iwithprefixbefore DIR'
  3559. Append DIR to the prefix specified previously with '-iprefix', and
  3560. add the resulting directory to the include search path.
  3561. '-iwithprefixbefore' puts it in the same place '-I' would;
  3562. '-iwithprefix' puts it where '-idirafter' would.
  3563. '-isysroot DIR'
  3564. This option is like the '--sysroot' option, but applies only to
  3565. header files (except for Darwin targets, where it applies to both
  3566. header files and libraries). See the '--sysroot' option for more
  3567. information.
  3568. '-imultilib DIR'
  3569. Use DIR as a subdirectory of the directory containing
  3570. target-specific C++ headers.
  3571. '-nostdinc'
  3572. Do not search the standard system directories for header files.
  3573. Only the directories explicitly specified with '-I', '-iquote',
  3574. '-isystem', and/or '-idirafter' options (and the directory of the
  3575. current file, if appropriate) are searched.
  3576. '-nostdinc++'
  3577. Do not search for header files in the C++-specific standard
  3578. directories, but do still search the other standard directories.
  3579. (This option is used when building the C++ library.)
  3580. '-Wcomment'
  3581. '-Wcomments'
  3582. Warn whenever a comment-start sequence '/*' appears in a '/*'
  3583. comment, or whenever a backslash-newline appears in a '//' comment.
  3584. This warning is enabled by '-Wall'.
  3585. '-Wtrigraphs'
  3586. Warn if any trigraphs are encountered that might change the meaning
  3587. of the program. Trigraphs within comments are not warned about,
  3588. except those that would form escaped newlines.
  3589. This option is implied by '-Wall'. If '-Wall' is not given, this
  3590. option is still enabled unless trigraphs are enabled. To get
  3591. trigraph conversion without warnings, but get the other '-Wall'
  3592. warnings, use '-trigraphs -Wall -Wno-trigraphs'.
  3593. '-Wundef'
  3594. Warn if an undefined identifier is evaluated in an '#if' directive.
  3595. Such identifiers are replaced with zero.
  3596. '-Wexpansion-to-defined'
  3597. Warn whenever 'defined' is encountered in the expansion of a macro
  3598. (including the case where the macro is expanded by an '#if'
  3599. directive). Such usage is not portable. This warning is also
  3600. enabled by '-Wpedantic' and '-Wextra'.
  3601. '-Wunused-macros'
  3602. Warn about macros defined in the main file that are unused. A
  3603. macro is "used" if it is expanded or tested for existence at least
  3604. once. The preprocessor also warns if the macro has not been used
  3605. at the time it is redefined or undefined.
  3606. Built-in macros, macros defined on the command line, and macros
  3607. defined in include files are not warned about.
  3608. _Note:_ If a macro is actually used, but only used in skipped
  3609. conditional blocks, then the preprocessor reports it as unused. To
  3610. avoid the warning in such a case, you might improve the scope of
  3611. the macro's definition by, for example, moving it into the first
  3612. skipped block. Alternatively, you could provide a dummy use with
  3613. something like:
  3614. #if defined the_macro_causing_the_warning
  3615. #endif
  3616. '-Wno-endif-labels'
  3617. Do not warn whenever an '#else' or an '#endif' are followed by
  3618. text. This sometimes happens in older programs with code of the
  3619. form
  3620. #if FOO
  3621. ...
  3622. #else FOO
  3623. ...
  3624. #endif FOO
  3625. The second and third 'FOO' should be in comments. This warning is
  3626. on by default.
  3627. 
  3628. File: cpp.info, Node: Environment Variables, Next: GNU Free Documentation License, Prev: Invocation, Up: Top
  3629. 13 Environment Variables
  3630. ************************
  3631. This section describes the environment variables that affect how CPP
  3632. operates. You can use them to specify directories or prefixes to use
  3633. when searching for include files, or to control dependency output.
  3634. Note that you can also specify places to search using options such as
  3635. '-I', and control dependency output with options like '-M' (*note
  3636. Invocation::). These take precedence over environment variables, which
  3637. in turn take precedence over the configuration of GCC.
  3638. 'CPATH'
  3639. 'C_INCLUDE_PATH'
  3640. 'CPLUS_INCLUDE_PATH'
  3641. 'OBJC_INCLUDE_PATH'
  3642. Each variable's value is a list of directories separated by a
  3643. special character, much like 'PATH', in which to look for header
  3644. files. The special character, 'PATH_SEPARATOR', is
  3645. target-dependent and determined at GCC build time. For Microsoft
  3646. Windows-based targets it is a semicolon, and for almost all other
  3647. targets it is a colon.
  3648. 'CPATH' specifies a list of directories to be searched as if
  3649. specified with '-I', but after any paths given with '-I' options on
  3650. the command line. This environment variable is used regardless of
  3651. which language is being preprocessed.
  3652. The remaining environment variables apply only when preprocessing
  3653. the particular language indicated. Each specifies a list of
  3654. directories to be searched as if specified with '-isystem', but
  3655. after any paths given with '-isystem' options on the command line.
  3656. In all these variables, an empty element instructs the compiler to
  3657. search its current working directory. Empty elements can appear at
  3658. the beginning or end of a path. For instance, if the value of
  3659. 'CPATH' is ':/special/include', that has the same effect as
  3660. '-I. -I/special/include'.
  3661. See also *note Search Path::.
  3662. 'DEPENDENCIES_OUTPUT'
  3663. If this variable is set, its value specifies how to output
  3664. dependencies for Make based on the non-system header files
  3665. processed by the compiler. System header files are ignored in the
  3666. dependency output.
  3667. The value of 'DEPENDENCIES_OUTPUT' can be just a file name, in
  3668. which case the Make rules are written to that file, guessing the
  3669. target name from the source file name. Or the value can have the
  3670. form 'FILE TARGET', in which case the rules are written to file
  3671. FILE using TARGET as the target name.
  3672. In other words, this environment variable is equivalent to
  3673. combining the options '-MM' and '-MF' (*note Invocation::), with an
  3674. optional '-MT' switch too.
  3675. 'SUNPRO_DEPENDENCIES'
  3676. This variable is the same as 'DEPENDENCIES_OUTPUT' (see above),
  3677. except that system header files are not ignored, so it implies '-M'
  3678. rather than '-MM'. However, the dependence on the main input file
  3679. is omitted. *Note Invocation::.
  3680. 'SOURCE_DATE_EPOCH'
  3681. If this variable is set, its value specifies a UNIX timestamp to be
  3682. used in replacement of the current date and time in the '__DATE__'
  3683. and '__TIME__' macros, so that the embedded timestamps become
  3684. reproducible.
  3685. The value of 'SOURCE_DATE_EPOCH' must be a UNIX timestamp, defined
  3686. as the number of seconds (excluding leap seconds) since 01 Jan 1970
  3687. 00:00:00 represented in ASCII; identical to the output of ''date
  3688. +%s'' on GNU/Linux and other systems that support the '%s'
  3689. extension in the 'date' command.
  3690. The value should be a known timestamp such as the last modification
  3691. time of the source or package and it should be set by the build
  3692. process.
  3693. 
  3694. File: cpp.info, Node: GNU Free Documentation License, Next: Index of Directives, Prev: Environment Variables, Up: Top
  3695. GNU Free Documentation License
  3696. ******************************
  3697. Version 1.3, 3 November 2008
  3698. Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
  3699. <http://fsf.org/>
  3700. Everyone is permitted to copy and distribute verbatim copies
  3701. of this license document, but changing it is not allowed.
  3702. 0. PREAMBLE
  3703. The purpose of this License is to make a manual, textbook, or other
  3704. functional and useful document "free" in the sense of freedom: to
  3705. assure everyone the effective freedom to copy and redistribute it,
  3706. with or without modifying it, either commercially or
  3707. noncommercially. Secondarily, this License preserves for the
  3708. author and publisher a way to get credit for their work, while not
  3709. being considered responsible for modifications made by others.
  3710. This License is a kind of "copyleft", which means that derivative
  3711. works of the document must themselves be free in the same sense.
  3712. It complements the GNU General Public License, which is a copyleft
  3713. license designed for free software.
  3714. We have designed this License in order to use it for manuals for
  3715. free software, because free software needs free documentation: a
  3716. free program should come with manuals providing the same freedoms
  3717. that the software does. But this License is not limited to
  3718. software manuals; it can be used for any textual work, regardless
  3719. of subject matter or whether it is published as a printed book. We
  3720. recommend this License principally for works whose purpose is
  3721. instruction or reference.
  3722. 1. APPLICABILITY AND DEFINITIONS
  3723. This License applies to any manual or other work, in any medium,
  3724. that contains a notice placed by the copyright holder saying it can
  3725. be distributed under the terms of this License. Such a notice
  3726. grants a world-wide, royalty-free license, unlimited in duration,
  3727. to use that work under the conditions stated herein. The
  3728. "Document", below, refers to any such manual or work. Any member
  3729. of the public is a licensee, and is addressed as "you". You accept
  3730. the license if you copy, modify or distribute the work in a way
  3731. requiring permission under copyright law.
  3732. A "Modified Version" of the Document means any work containing the
  3733. Document or a portion of it, either copied verbatim, or with
  3734. modifications and/or translated into another language.
  3735. A "Secondary Section" is a named appendix or a front-matter section
  3736. of the Document that deals exclusively with the relationship of the
  3737. publishers or authors of the Document to the Document's overall
  3738. subject (or to related matters) and contains nothing that could
  3739. fall directly within that overall subject. (Thus, if the Document
  3740. is in part a textbook of mathematics, a Secondary Section may not
  3741. explain any mathematics.) The relationship could be a matter of
  3742. historical connection with the subject or with related matters, or
  3743. of legal, commercial, philosophical, ethical or political position
  3744. regarding them.
  3745. The "Invariant Sections" are certain Secondary Sections whose
  3746. titles are designated, as being those of Invariant Sections, in the
  3747. notice that says that the Document is released under this License.
  3748. If a section does not fit the above definition of Secondary then it
  3749. is not allowed to be designated as Invariant. The Document may
  3750. contain zero Invariant Sections. If the Document does not identify
  3751. any Invariant Sections then there are none.
  3752. The "Cover Texts" are certain short passages of text that are
  3753. listed, as Front-Cover Texts or Back-Cover Texts, in the notice
  3754. that says that the Document is released under this License. A
  3755. Front-Cover Text may be at most 5 words, and a Back-Cover Text may
  3756. be at most 25 words.
  3757. A "Transparent" copy of the Document means a machine-readable copy,
  3758. represented in a format whose specification is available to the
  3759. general public, that is suitable for revising the document
  3760. straightforwardly with generic text editors or (for images composed
  3761. of pixels) generic paint programs or (for drawings) some widely
  3762. available drawing editor, and that is suitable for input to text
  3763. formatters or for automatic translation to a variety of formats
  3764. suitable for input to text formatters. A copy made in an otherwise
  3765. Transparent file format whose markup, or absence of markup, has
  3766. been arranged to thwart or discourage subsequent modification by
  3767. readers is not Transparent. An image format is not Transparent if
  3768. used for any substantial amount of text. A copy that is not
  3769. "Transparent" is called "Opaque".
  3770. Examples of suitable formats for Transparent copies include plain
  3771. ASCII without markup, Texinfo input format, LaTeX input format,
  3772. SGML or XML using a publicly available DTD, and standard-conforming
  3773. simple HTML, PostScript or PDF designed for human modification.
  3774. Examples of transparent image formats include PNG, XCF and JPG.
  3775. Opaque formats include proprietary formats that can be read and
  3776. edited only by proprietary word processors, SGML or XML for which
  3777. the DTD and/or processing tools are not generally available, and
  3778. the machine-generated HTML, PostScript or PDF produced by some word
  3779. processors for output purposes only.
  3780. The "Title Page" means, for a printed book, the title page itself,
  3781. plus such following pages as are needed to hold, legibly, the
  3782. material this License requires to appear in the title page. For
  3783. works in formats which do not have any title page as such, "Title
  3784. Page" means the text near the most prominent appearance of the
  3785. work's title, preceding the beginning of the body of the text.
  3786. The "publisher" means any person or entity that distributes copies
  3787. of the Document to the public.
  3788. A section "Entitled XYZ" means a named subunit of the Document
  3789. whose title either is precisely XYZ or contains XYZ in parentheses
  3790. following text that translates XYZ in another language. (Here XYZ
  3791. stands for a specific section name mentioned below, such as
  3792. "Acknowledgements", "Dedications", "Endorsements", or "History".)
  3793. To "Preserve the Title" of such a section when you modify the
  3794. Document means that it remains a section "Entitled XYZ" according
  3795. to this definition.
  3796. The Document may include Warranty Disclaimers next to the notice
  3797. which states that this License applies to the Document. These
  3798. Warranty Disclaimers are considered to be included by reference in
  3799. this License, but only as regards disclaiming warranties: any other
  3800. implication that these Warranty Disclaimers may have is void and
  3801. has no effect on the meaning of this License.
  3802. 2. VERBATIM COPYING
  3803. You may copy and distribute the Document in any medium, either
  3804. commercially or noncommercially, provided that this License, the
  3805. copyright notices, and the license notice saying this License
  3806. applies to the Document are reproduced in all copies, and that you
  3807. add no other conditions whatsoever to those of this License. You
  3808. may not use technical measures to obstruct or control the reading
  3809. or further copying of the copies you make or distribute. However,
  3810. you may accept compensation in exchange for copies. If you
  3811. distribute a large enough number of copies you must also follow the
  3812. conditions in section 3.
  3813. You may also lend copies, under the same conditions stated above,
  3814. and you may publicly display copies.
  3815. 3. COPYING IN QUANTITY
  3816. If you publish printed copies (or copies in media that commonly
  3817. have printed covers) of the Document, numbering more than 100, and
  3818. the Document's license notice requires Cover Texts, you must
  3819. enclose the copies in covers that carry, clearly and legibly, all
  3820. these Cover Texts: Front-Cover Texts on the front cover, and
  3821. Back-Cover Texts on the back cover. Both covers must also clearly
  3822. and legibly identify you as the publisher of these copies. The
  3823. front cover must present the full title with all words of the title
  3824. equally prominent and visible. You may add other material on the
  3825. covers in addition. Copying with changes limited to the covers, as
  3826. long as they preserve the title of the Document and satisfy these
  3827. conditions, can be treated as verbatim copying in other respects.
  3828. If the required texts for either cover are too voluminous to fit
  3829. legibly, you should put the first ones listed (as many as fit
  3830. reasonably) on the actual cover, and continue the rest onto
  3831. adjacent pages.
  3832. If you publish or distribute Opaque copies of the Document
  3833. numbering more than 100, you must either include a machine-readable
  3834. Transparent copy along with each Opaque copy, or state in or with
  3835. each Opaque copy a computer-network location from which the general
  3836. network-using public has access to download using public-standard
  3837. network protocols a complete Transparent copy of the Document, free
  3838. of added material. If you use the latter option, you must take
  3839. reasonably prudent steps, when you begin distribution of Opaque
  3840. copies in quantity, to ensure that this Transparent copy will
  3841. remain thus accessible at the stated location until at least one
  3842. year after the last time you distribute an Opaque copy (directly or
  3843. through your agents or retailers) of that edition to the public.
  3844. It is requested, but not required, that you contact the authors of
  3845. the Document well before redistributing any large number of copies,
  3846. to give them a chance to provide you with an updated version of the
  3847. Document.
  3848. 4. MODIFICATIONS
  3849. You may copy and distribute a Modified Version of the Document
  3850. under the conditions of sections 2 and 3 above, provided that you
  3851. release the Modified Version under precisely this License, with the
  3852. Modified Version filling the role of the Document, thus licensing
  3853. distribution and modification of the Modified Version to whoever
  3854. possesses a copy of it. In addition, you must do these things in
  3855. the Modified Version:
  3856. A. Use in the Title Page (and on the covers, if any) a title
  3857. distinct from that of the Document, and from those of previous
  3858. versions (which should, if there were any, be listed in the
  3859. History section of the Document). You may use the same title
  3860. as a previous version if the original publisher of that
  3861. version gives permission.
  3862. B. List on the Title Page, as authors, one or more persons or
  3863. entities responsible for authorship of the modifications in
  3864. the Modified Version, together with at least five of the
  3865. principal authors of the Document (all of its principal
  3866. authors, if it has fewer than five), unless they release you
  3867. from this requirement.
  3868. C. State on the Title page the name of the publisher of the
  3869. Modified Version, as the publisher.
  3870. D. Preserve all the copyright notices of the Document.
  3871. E. Add an appropriate copyright notice for your modifications
  3872. adjacent to the other copyright notices.
  3873. F. Include, immediately after the copyright notices, a license
  3874. notice giving the public permission to use the Modified
  3875. Version under the terms of this License, in the form shown in
  3876. the Addendum below.
  3877. G. Preserve in that license notice the full lists of Invariant
  3878. Sections and required Cover Texts given in the Document's
  3879. license notice.
  3880. H. Include an unaltered copy of this License.
  3881. I. Preserve the section Entitled "History", Preserve its Title,
  3882. and add to it an item stating at least the title, year, new
  3883. authors, and publisher of the Modified Version as given on the
  3884. Title Page. If there is no section Entitled "History" in the
  3885. Document, create one stating the title, year, authors, and
  3886. publisher of the Document as given on its Title Page, then add
  3887. an item describing the Modified Version as stated in the
  3888. previous sentence.
  3889. J. Preserve the network location, if any, given in the Document
  3890. for public access to a Transparent copy of the Document, and
  3891. likewise the network locations given in the Document for
  3892. previous versions it was based on. These may be placed in the
  3893. "History" section. You may omit a network location for a work
  3894. that was published at least four years before the Document
  3895. itself, or if the original publisher of the version it refers
  3896. to gives permission.
  3897. K. For any section Entitled "Acknowledgements" or "Dedications",
  3898. Preserve the Title of the section, and preserve in the section
  3899. all the substance and tone of each of the contributor
  3900. acknowledgements and/or dedications given therein.
  3901. L. Preserve all the Invariant Sections of the Document, unaltered
  3902. in their text and in their titles. Section numbers or the
  3903. equivalent are not considered part of the section titles.
  3904. M. Delete any section Entitled "Endorsements". Such a section
  3905. may not be included in the Modified Version.
  3906. N. Do not retitle any existing section to be Entitled
  3907. "Endorsements" or to conflict in title with any Invariant
  3908. Section.
  3909. O. Preserve any Warranty Disclaimers.
  3910. If the Modified Version includes new front-matter sections or
  3911. appendices that qualify as Secondary Sections and contain no
  3912. material copied from the Document, you may at your option designate
  3913. some or all of these sections as invariant. To do this, add their
  3914. titles to the list of Invariant Sections in the Modified Version's
  3915. license notice. These titles must be distinct from any other
  3916. section titles.
  3917. You may add a section Entitled "Endorsements", provided it contains
  3918. nothing but endorsements of your Modified Version by various
  3919. parties--for example, statements of peer review or that the text
  3920. has been approved by an organization as the authoritative
  3921. definition of a standard.
  3922. You may add a passage of up to five words as a Front-Cover Text,
  3923. and a passage of up to 25 words as a Back-Cover Text, to the end of
  3924. the list of Cover Texts in the Modified Version. Only one passage
  3925. of Front-Cover Text and one of Back-Cover Text may be added by (or
  3926. through arrangements made by) any one entity. If the Document
  3927. already includes a cover text for the same cover, previously added
  3928. by you or by arrangement made by the same entity you are acting on
  3929. behalf of, you may not add another; but you may replace the old
  3930. one, on explicit permission from the previous publisher that added
  3931. the old one.
  3932. The author(s) and publisher(s) of the Document do not by this
  3933. License give permission to use their names for publicity for or to
  3934. assert or imply endorsement of any Modified Version.
  3935. 5. COMBINING DOCUMENTS
  3936. You may combine the Document with other documents released under
  3937. this License, under the terms defined in section 4 above for
  3938. modified versions, provided that you include in the combination all
  3939. of the Invariant Sections of all of the original documents,
  3940. unmodified, and list them all as Invariant Sections of your
  3941. combined work in its license notice, and that you preserve all
  3942. their Warranty Disclaimers.
  3943. The combined work need only contain one copy of this License, and
  3944. multiple identical Invariant Sections may be replaced with a single
  3945. copy. If there are multiple Invariant Sections with the same name
  3946. but different contents, make the title of each such section unique
  3947. by adding at the end of it, in parentheses, the name of the
  3948. original author or publisher of that section if known, or else a
  3949. unique number. Make the same adjustment to the section titles in
  3950. the list of Invariant Sections in the license notice of the
  3951. combined work.
  3952. In the combination, you must combine any sections Entitled
  3953. "History" in the various original documents, forming one section
  3954. Entitled "History"; likewise combine any sections Entitled
  3955. "Acknowledgements", and any sections Entitled "Dedications". You
  3956. must delete all sections Entitled "Endorsements."
  3957. 6. COLLECTIONS OF DOCUMENTS
  3958. You may make a collection consisting of the Document and other
  3959. documents released under this License, and replace the individual
  3960. copies of this License in the various documents with a single copy
  3961. that is included in the collection, provided that you follow the
  3962. rules of this License for verbatim copying of each of the documents
  3963. in all other respects.
  3964. You may extract a single document from such a collection, and
  3965. distribute it individually under this License, provided you insert
  3966. a copy of this License into the extracted document, and follow this
  3967. License in all other respects regarding verbatim copying of that
  3968. document.
  3969. 7. AGGREGATION WITH INDEPENDENT WORKS
  3970. A compilation of the Document or its derivatives with other
  3971. separate and independent documents or works, in or on a volume of a
  3972. storage or distribution medium, is called an "aggregate" if the
  3973. copyright resulting from the compilation is not used to limit the
  3974. legal rights of the compilation's users beyond what the individual
  3975. works permit. When the Document is included in an aggregate, this
  3976. License does not apply to the other works in the aggregate which
  3977. are not themselves derivative works of the Document.
  3978. If the Cover Text requirement of section 3 is applicable to these
  3979. copies of the Document, then if the Document is less than one half
  3980. of the entire aggregate, the Document's Cover Texts may be placed
  3981. on covers that bracket the Document within the aggregate, or the
  3982. electronic equivalent of covers if the Document is in electronic
  3983. form. Otherwise they must appear on printed covers that bracket
  3984. the whole aggregate.
  3985. 8. TRANSLATION
  3986. Translation is considered a kind of modification, so you may
  3987. distribute translations of the Document under the terms of section
  3988. 4. Replacing Invariant Sections with translations requires special
  3989. permission from their copyright holders, but you may include
  3990. translations of some or all Invariant Sections in addition to the
  3991. original versions of these Invariant Sections. You may include a
  3992. translation of this License, and all the license notices in the
  3993. Document, and any Warranty Disclaimers, provided that you also
  3994. include the original English version of this License and the
  3995. original versions of those notices and disclaimers. In case of a
  3996. disagreement between the translation and the original version of
  3997. this License or a notice or disclaimer, the original version will
  3998. prevail.
  3999. If a section in the Document is Entitled "Acknowledgements",
  4000. "Dedications", or "History", the requirement (section 4) to
  4001. Preserve its Title (section 1) will typically require changing the
  4002. actual title.
  4003. 9. TERMINATION
  4004. You may not copy, modify, sublicense, or distribute the Document
  4005. except as expressly provided under this License. Any attempt
  4006. otherwise to copy, modify, sublicense, or distribute it is void,
  4007. and will automatically terminate your rights under this License.
  4008. However, if you cease all violation of this License, then your
  4009. license from a particular copyright holder is reinstated (a)
  4010. provisionally, unless and until the copyright holder explicitly and
  4011. finally terminates your license, and (b) permanently, if the
  4012. copyright holder fails to notify you of the violation by some
  4013. reasonable means prior to 60 days after the cessation.
  4014. Moreover, your license from a particular copyright holder is
  4015. reinstated permanently if the copyright holder notifies you of the
  4016. violation by some reasonable means, this is the first time you have
  4017. received notice of violation of this License (for any work) from
  4018. that copyright holder, and you cure the violation prior to 30 days
  4019. after your receipt of the notice.
  4020. Termination of your rights under this section does not terminate
  4021. the licenses of parties who have received copies or rights from you
  4022. under this License. If your rights have been terminated and not
  4023. permanently reinstated, receipt of a copy of some or all of the
  4024. same material does not give you any rights to use it.
  4025. 10. FUTURE REVISIONS OF THIS LICENSE
  4026. The Free Software Foundation may publish new, revised versions of
  4027. the GNU Free Documentation License from time to time. Such new
  4028. versions will be similar in spirit to the present version, but may
  4029. differ in detail to address new problems or concerns. See
  4030. <http://www.gnu.org/copyleft/>.
  4031. Each version of the License is given a distinguishing version
  4032. number. If the Document specifies that a particular numbered
  4033. version of this License "or any later version" applies to it, you
  4034. have the option of following the terms and conditions either of
  4035. that specified version or of any later version that has been
  4036. published (not as a draft) by the Free Software Foundation. If the
  4037. Document does not specify a version number of this License, you may
  4038. choose any version ever published (not as a draft) by the Free
  4039. Software Foundation. If the Document specifies that a proxy can
  4040. decide which future versions of this License can be used, that
  4041. proxy's public statement of acceptance of a version permanently
  4042. authorizes you to choose that version for the Document.
  4043. 11. RELICENSING
  4044. "Massive Multiauthor Collaboration Site" (or "MMC Site") means any
  4045. World Wide Web server that publishes copyrightable works and also
  4046. provides prominent facilities for anybody to edit those works. A
  4047. public wiki that anybody can edit is an example of such a server.
  4048. A "Massive Multiauthor Collaboration" (or "MMC") contained in the
  4049. site means any set of copyrightable works thus published on the MMC
  4050. site.
  4051. "CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0
  4052. license published by Creative Commons Corporation, a not-for-profit
  4053. corporation with a principal place of business in San Francisco,
  4054. California, as well as future copyleft versions of that license
  4055. published by that same organization.
  4056. "Incorporate" means to publish or republish a Document, in whole or
  4057. in part, as part of another Document.
  4058. An MMC is "eligible for relicensing" if it is licensed under this
  4059. License, and if all works that were first published under this
  4060. License somewhere other than this MMC, and subsequently
  4061. incorporated in whole or in part into the MMC, (1) had no cover
  4062. texts or invariant sections, and (2) were thus incorporated prior
  4063. to November 1, 2008.
  4064. The operator of an MMC Site may republish an MMC contained in the
  4065. site under CC-BY-SA on the same site at any time before August 1,
  4066. 2009, provided the MMC is eligible for relicensing.
  4067. ADDENDUM: How to use this License for your documents
  4068. ====================================================
  4069. To use this License in a document you have written, include a copy of
  4070. the License in the document and put the following copyright and license
  4071. notices just after the title page:
  4072. Copyright (C) YEAR YOUR NAME.
  4073. Permission is granted to copy, distribute and/or modify this document
  4074. under the terms of the GNU Free Documentation License, Version 1.3
  4075. or any later version published by the Free Software Foundation;
  4076. with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
  4077. Texts. A copy of the license is included in the section entitled ``GNU
  4078. Free Documentation License''.
  4079. If you have Invariant Sections, Front-Cover Texts and Back-Cover
  4080. Texts, replace the "with...Texts." line with this:
  4081. with the Invariant Sections being LIST THEIR TITLES, with
  4082. the Front-Cover Texts being LIST, and with the Back-Cover Texts
  4083. being LIST.
  4084. If you have Invariant Sections without Cover Texts, or some other
  4085. combination of the three, merge those two alternatives to suit the
  4086. situation.
  4087. If your document contains nontrivial examples of program code, we
  4088. recommend releasing these examples in parallel under your choice of free
  4089. software license, such as the GNU General Public License, to permit
  4090. their use in free software.
  4091. 
  4092. File: cpp.info, Node: Index of Directives, Next: Option Index, Prev: GNU Free Documentation License, Up: Top
  4093. Index of Directives
  4094. *******************
  4095. �[index�]
  4096. * Menu:
  4097. * #assert: Obsolete Features. (line 48)
  4098. * #define: Object-like Macros. (line 11)
  4099. * #elif: Elif. (line 6)
  4100. * #else: Else. (line 6)
  4101. * #endif: Ifdef. (line 6)
  4102. * #error: Diagnostics. (line 6)
  4103. * #ident: Other Directives. (line 6)
  4104. * #if: Conditional Syntax. (line 6)
  4105. * #ifdef: Ifdef. (line 6)
  4106. * #ifndef: Ifdef. (line 40)
  4107. * #import: Alternatives to Wrapper #ifndef.
  4108. (line 11)
  4109. * #include: Include Syntax. (line 6)
  4110. * #include_next: Wrapper Headers. (line 6)
  4111. * #line: Line Control. (line 20)
  4112. * #pragma GCC dependency: Pragmas. (line 43)
  4113. * #pragma GCC error: Pragmas. (line 88)
  4114. * #pragma GCC poison: Pragmas. (line 55)
  4115. * #pragma GCC system_header: System Headers. (line 25)
  4116. * #pragma GCC system_header <1>: Pragmas. (line 82)
  4117. * #pragma GCC warning: Pragmas. (line 87)
  4118. * #pragma once: Pragmas. (line 96)
  4119. * #sccs: Other Directives. (line 6)
  4120. * #unassert: Obsolete Features. (line 59)
  4121. * #undef: Undefining and Redefining Macros.
  4122. (line 6)
  4123. * #warning: Diagnostics. (line 27)
  4124. 
  4125. File: cpp.info, Node: Option Index, Next: Concept Index, Prev: Index of Directives, Up: Top
  4126. Option Index
  4127. ************
  4128. CPP's command-line options and environment variables are indexed here
  4129. without any initial '-' or '--'.
  4130. �[index�]
  4131. * Menu:
  4132. * A: Invocation. (line 329)
  4133. * C: Invocation. (line 338)
  4134. * CC: Invocation. (line 350)
  4135. * CPATH: Environment Variables.
  4136. (line 15)
  4137. * CPLUS_INCLUDE_PATH: Environment Variables.
  4138. (line 17)
  4139. * C_INCLUDE_PATH: Environment Variables.
  4140. (line 16)
  4141. * D: Invocation. (line 44)
  4142. * d: Invocation. (line 399)
  4143. * dD: Invocation. (line 418)
  4144. * DEPENDENCIES_OUTPUT: Environment Variables.
  4145. (line 45)
  4146. * dI: Invocation. (line 428)
  4147. * dM: Invocation. (line 407)
  4148. * dN: Invocation. (line 424)
  4149. * dU: Invocation. (line 432)
  4150. * fdebug-cpp: Invocation. (line 439)
  4151. * fdirectives-only: Invocation. (line 228)
  4152. * fdollars-in-identifiers: Invocation. (line 249)
  4153. * fexec-charset: Invocation. (line 292)
  4154. * fextended-identifiers: Invocation. (line 252)
  4155. * finput-charset: Invocation. (line 305)
  4156. * fmacro-prefix-map: Invocation. (line 283)
  4157. * fno-canonical-system-headers: Invocation. (line 256)
  4158. * fno-working-directory: Invocation. (line 315)
  4159. * fpreprocessed: Invocation. (line 215)
  4160. * ftabstop: Invocation. (line 260)
  4161. * ftrack-macro-expansion: Invocation. (line 266)
  4162. * fwide-exec-charset: Invocation. (line 297)
  4163. * fworking-directory: Invocation. (line 315)
  4164. * H: Invocation. (line 392)
  4165. * I: Invocation. (line 450)
  4166. * I-: Invocation. (line 504)
  4167. * idirafter: Invocation. (line 450)
  4168. * imacros: Invocation. (line 82)
  4169. * imultilib: Invocation. (line 538)
  4170. * include: Invocation. (line 71)
  4171. * iprefix: Invocation. (line 520)
  4172. * iquote: Invocation. (line 450)
  4173. * isysroot: Invocation. (line 532)
  4174. * isystem: Invocation. (line 450)
  4175. * iwithprefix: Invocation. (line 526)
  4176. * iwithprefixbefore: Invocation. (line 526)
  4177. * M: Invocation. (line 103)
  4178. * MD: Invocation. (line 195)
  4179. * MF: Invocation. (line 137)
  4180. * MG: Invocation. (line 148)
  4181. * MM: Invocation. (line 128)
  4182. * MMD: Invocation. (line 211)
  4183. * MP: Invocation. (line 158)
  4184. * MQ: Invocation. (line 185)
  4185. * MT: Invocation. (line 170)
  4186. * nostdinc: Invocation. (line 542)
  4187. * nostdinc++: Invocation. (line 548)
  4188. * OBJC_INCLUDE_PATH: Environment Variables.
  4189. (line 18)
  4190. * P: Invocation. (line 362)
  4191. * pthread: Invocation. (line 96)
  4192. * remap: Invocation. (line 388)
  4193. * SOURCE_DATE_EPOCH: Environment Variables.
  4194. (line 67)
  4195. * SUNPRO_DEPENDENCIES: Environment Variables.
  4196. (line 61)
  4197. * traditional: Invocation. (line 370)
  4198. * traditional-cpp: Invocation. (line 370)
  4199. * trigraphs: Invocation. (line 379)
  4200. * U: Invocation. (line 67)
  4201. * undef: Invocation. (line 91)
  4202. * Wcomment: Invocation. (line 554)
  4203. * Wcomments: Invocation. (line 554)
  4204. * Wendif-labels: Invocation. (line 598)
  4205. * Wexpansion-to-defined: Invocation. (line 573)
  4206. * Wno-endif-labels: Invocation. (line 598)
  4207. * Wno-undef: Invocation. (line 569)
  4208. * Wtrigraphs: Invocation. (line 559)
  4209. * Wundef: Invocation. (line 569)
  4210. * Wunused-macros: Invocation. (line 579)
  4211. 
  4212. File: cpp.info, Node: Concept Index, Prev: Option Index, Up: Top
  4213. Concept Index
  4214. *************
  4215. �[index�]
  4216. * Menu:
  4217. * # operator: Stringizing. (line 6)
  4218. * ## operator: Concatenation. (line 6)
  4219. * _Pragma: Pragmas. (line 13)
  4220. * __has_attribute: __has_attribute. (line 6)
  4221. * __has_cpp_attribute: __has_cpp_attribute. (line 6)
  4222. * __has_include: __has_include. (line 6)
  4223. * alternative tokens: Tokenization. (line 101)
  4224. * arguments: Macro Arguments. (line 6)
  4225. * arguments in macro definitions: Macro Arguments. (line 6)
  4226. * assertions: Obsolete Features. (line 13)
  4227. * assertions, canceling: Obsolete Features. (line 59)
  4228. * backslash-newline: Initial processing. (line 61)
  4229. * block comments: Initial processing. (line 77)
  4230. * C language, traditional: Invocation. (line 368)
  4231. * C++ named operators: C++ Named Operators. (line 6)
  4232. * character constants: Tokenization. (line 82)
  4233. * character set, execution: Invocation. (line 292)
  4234. * character set, input: Invocation. (line 305)
  4235. * character set, wide execution: Invocation. (line 297)
  4236. * command line: Invocation. (line 6)
  4237. * commenting out code: Deleted Code. (line 6)
  4238. * comments: Initial processing. (line 77)
  4239. * common predefined macros: Common Predefined Macros.
  4240. (line 6)
  4241. * computed includes: Computed Includes. (line 6)
  4242. * concatenation: Concatenation. (line 6)
  4243. * conditional group: Ifdef. (line 14)
  4244. * conditionals: Conditionals. (line 6)
  4245. * continued lines: Initial processing. (line 61)
  4246. * controlling macro: Once-Only Headers. (line 35)
  4247. * defined: Defined. (line 6)
  4248. * dependencies for make as output: Environment Variables.
  4249. (line 46)
  4250. * dependencies for make as output <1>: Environment Variables.
  4251. (line 62)
  4252. * dependencies, make: Invocation. (line 103)
  4253. * diagnostic: Diagnostics. (line 6)
  4254. * digraphs: Tokenization. (line 101)
  4255. * directive line: The preprocessing language.
  4256. (line 6)
  4257. * directive name: The preprocessing language.
  4258. (line 6)
  4259. * directives: The preprocessing language.
  4260. (line 6)
  4261. * empty macro arguments: Macro Arguments. (line 66)
  4262. * environment variables: Environment Variables.
  4263. (line 6)
  4264. * expansion of arguments: Argument Prescan. (line 6)
  4265. * FDL, GNU Free Documentation License: GNU Free Documentation License.
  4266. (line 6)
  4267. * function-like macros: Function-like Macros.
  4268. (line 6)
  4269. * grouping options: Invocation. (line 38)
  4270. * guard macro: Once-Only Headers. (line 35)
  4271. * header file: Header Files. (line 6)
  4272. * header file names: Tokenization. (line 82)
  4273. * identifiers: Tokenization. (line 33)
  4274. * implementation limits: Implementation limits.
  4275. (line 6)
  4276. * implementation-defined behavior: Implementation-defined behavior.
  4277. (line 6)
  4278. * including just once: Once-Only Headers. (line 6)
  4279. * invocation: Invocation. (line 6)
  4280. * iso646.h: C++ Named Operators. (line 6)
  4281. * line comments: Initial processing. (line 77)
  4282. * line control: Line Control. (line 6)
  4283. * line endings: Initial processing. (line 14)
  4284. * linemarkers: Preprocessor Output. (line 27)
  4285. * macro argument expansion: Argument Prescan. (line 6)
  4286. * macro arguments and directives: Directives Within Macro Arguments.
  4287. (line 6)
  4288. * macros in include: Computed Includes. (line 6)
  4289. * macros with arguments: Macro Arguments. (line 6)
  4290. * macros with variable arguments: Variadic Macros. (line 6)
  4291. * make: Invocation. (line 103)
  4292. * manifest constants: Object-like Macros. (line 6)
  4293. * named operators: C++ Named Operators. (line 6)
  4294. * newlines in macro arguments: Newlines in Arguments.
  4295. (line 6)
  4296. * null directive: Other Directives. (line 15)
  4297. * numbers: Tokenization. (line 59)
  4298. * object-like macro: Object-like Macros. (line 6)
  4299. * options: Invocation. (line 43)
  4300. * options, grouping: Invocation. (line 38)
  4301. * other tokens: Tokenization. (line 115)
  4302. * output format: Preprocessor Output. (line 12)
  4303. * overriding a header file: Wrapper Headers. (line 6)
  4304. * parentheses in macro bodies: Operator Precedence Problems.
  4305. (line 6)
  4306. * pitfalls of macros: Macro Pitfalls. (line 6)
  4307. * pragma directive: Pragmas. (line 6)
  4308. * predefined macros: Predefined Macros. (line 6)
  4309. * predefined macros, system-specific: System-specific Predefined Macros.
  4310. (line 6)
  4311. * predicates: Obsolete Features. (line 26)
  4312. * preprocessing directives: The preprocessing language.
  4313. (line 6)
  4314. * preprocessing numbers: Tokenization. (line 59)
  4315. * preprocessing tokens: Tokenization. (line 6)
  4316. * prescan of macro arguments: Argument Prescan. (line 6)
  4317. * problems with macros: Macro Pitfalls. (line 6)
  4318. * punctuators: Tokenization. (line 101)
  4319. * redefining macros: Undefining and Redefining Macros.
  4320. (line 6)
  4321. * repeated inclusion: Once-Only Headers. (line 6)
  4322. * reporting errors: Diagnostics. (line 6)
  4323. * reporting warnings: Diagnostics. (line 6)
  4324. * reserved namespace: System-specific Predefined Macros.
  4325. (line 6)
  4326. * self-reference: Self-Referential Macros.
  4327. (line 6)
  4328. * semicolons (after macro calls): Swallowing the Semicolon.
  4329. (line 6)
  4330. * side effects (in macro arguments): Duplication of Side Effects.
  4331. (line 6)
  4332. * standard predefined macros.: Standard Predefined Macros.
  4333. (line 6)
  4334. * string constants: Tokenization. (line 82)
  4335. * string literals: Tokenization. (line 82)
  4336. * stringizing: Stringizing. (line 6)
  4337. * symbolic constants: Object-like Macros. (line 6)
  4338. * system header files: Header Files. (line 13)
  4339. * system header files <1>: System Headers. (line 6)
  4340. * system-specific predefined macros: System-specific Predefined Macros.
  4341. (line 6)
  4342. * testing predicates: Obsolete Features. (line 37)
  4343. * token concatenation: Concatenation. (line 6)
  4344. * token pasting: Concatenation. (line 6)
  4345. * tokens: Tokenization. (line 6)
  4346. * traditional C language: Invocation. (line 368)
  4347. * trigraphs: Initial processing. (line 32)
  4348. * undefining macros: Undefining and Redefining Macros.
  4349. (line 6)
  4350. * unsafe macros: Duplication of Side Effects.
  4351. (line 6)
  4352. * variable number of arguments: Variadic Macros. (line 6)
  4353. * variadic macros: Variadic Macros. (line 6)
  4354. * wrapper #ifndef: Once-Only Headers. (line 6)
  4355. * wrapper headers: Wrapper Headers. (line 6)
  4356. 
  4357. Tag Table:
  4358. Node: Top945
  4359. Node: Overview3506
  4360. Node: Character sets6344
  4361. Ref: Character sets-Footnote-18499
  4362. Node: Initial processing8680
  4363. Ref: trigraphs10239
  4364. Node: Tokenization14439
  4365. Ref: Tokenization-Footnote-121340
  4366. Node: The preprocessing language21451
  4367. Node: Header Files24330
  4368. Node: Include Syntax26246
  4369. Node: Include Operation27883
  4370. Node: Search Path29731
  4371. Node: Once-Only Headers31953
  4372. Node: Alternatives to Wrapper #ifndef33612
  4373. Node: Computed Includes35261
  4374. Node: Wrapper Headers38419
  4375. Node: System Headers40842
  4376. Node: Macros42443
  4377. Node: Object-like Macros43580
  4378. Node: Function-like Macros47170
  4379. Node: Macro Arguments48786
  4380. Node: Stringizing52925
  4381. Node: Concatenation56086
  4382. Node: Variadic Macros59183
  4383. Node: Predefined Macros64135
  4384. Node: Standard Predefined Macros64723
  4385. Node: Common Predefined Macros71055
  4386. Node: System-specific Predefined Macros92158
  4387. Node: C++ Named Operators94181
  4388. Node: Undefining and Redefining Macros95145
  4389. Node: Directives Within Macro Arguments97243
  4390. Node: Macro Pitfalls98184
  4391. Node: Misnesting98717
  4392. Node: Operator Precedence Problems99829
  4393. Node: Swallowing the Semicolon101695
  4394. Node: Duplication of Side Effects103718
  4395. Node: Self-Referential Macros105901
  4396. Node: Argument Prescan108310
  4397. Node: Newlines in Arguments112061
  4398. Node: Conditionals113012
  4399. Node: Conditional Uses114708
  4400. Node: Conditional Syntax116066
  4401. Node: Ifdef116448
  4402. Node: If119605
  4403. Node: Defined121909
  4404. Node: Else123302
  4405. Node: Elif123872
  4406. Node: __has_attribute125185
  4407. Node: __has_cpp_attribute126719
  4408. Node: __has_include127605
  4409. Node: Deleted Code129198
  4410. Node: Diagnostics130445
  4411. Node: Line Control131994
  4412. Node: Pragmas134272
  4413. Node: Other Directives138669
  4414. Node: Preprocessor Output139719
  4415. Node: Traditional Mode142872
  4416. Node: Traditional lexical analysis144009
  4417. Node: Traditional macros146512
  4418. Node: Traditional miscellany150309
  4419. Node: Traditional warnings151305
  4420. Node: Implementation Details153502
  4421. Node: Implementation-defined behavior154065
  4422. Ref: Identifier characters154815
  4423. Node: Implementation limits157682
  4424. Node: Obsolete Features160355
  4425. Node: Invocation163199
  4426. Ref: dashMF169234
  4427. Ref: fdollars-in-identifiers173813
  4428. Ref: Wtrigraphs187809
  4429. Node: Environment Variables189864
  4430. Node: GNU Free Documentation License193557
  4431. Node: Index of Directives218702
  4432. Node: Option Index220855
  4433. Node: Concept Index226811
  4434. 
  4435. End Tag Table