Pragma directives specify machine-specific or operating system-specific compiler features. A line that starts with #pragma specifies a pragma directive.
Pragma, an abbreviation for pragmatic, or from the same root, may refer to ... Pragma (periodical), a 1980's publication for Pick operating system users.
is for compiler directives that are machine-specific or operating-system-specific, i.e. it tells the compiler to do something, set some option, take some action, override some default, etc. that may or may not apply to all machines and operating systems.See msdn for more info.
25 Mart 2017
77 kişi değerlendirdi
1 yorum
{"2_9pcn":{"state":{"logo":{"href":"//yandex.com.tr","isForeign":true},"form":{"action":"/search/","searchLabel":"Bul","hiddenInputs":[{"name":"lr","value":21206}]},"actions":{"advancedSearch":{"checked":false,"ariaLabel":"Gelişmiş arama"},"moreButtonProps":{"ariaLabel":"Daha fazla"},"cbir":{"name":"cbir","label":"Поиск по картинке","infoUrl":"//yandex.ru/promo/photosearch/index?source=landingdesk","isMacOS":false}},"userSection":{"loggedIn":false,"loginProps":{"loginUrl":"https://passport.yandex.com.tr/auth?retpath=%2F&origin=serp_desktop_auth_new","loginText":"Giriş yap","burgerAriaLabel":"Menü"}},"navigation":{"tabs":[{"id":"www","label":"Arama","url":"//yandex.com.tr","params":{"source":"tabbar"},"target":""},{"id":"images","label":"Görsel","url":"//yandex.com.tr/gorsel/search","params":{"text":"[$query]","noreask":"[$noreask]","nomisspell":"[$nomisspell]","parent-reqid":"[$reqid]","from":"tabbar"}},{"id":"video","label":"Video","url":"//yandex.com.tr/video/search","params":{"text":"[$query]","parent-reqid":"[$reqid]","from":"tabbar"}},{"id":"maps","label":"Haritalar","url":"//yandex.com.tr/harita","params":{"text":"[$query]","source":"serp_navig"}},{"id":"translate","label":"Çeviri","url":"//ceviri.yandex.com.tr","params":{"text":"[$query]","from":"tabbar"}}],"selectedTabId":"www","fixedTabsCount":1},"context":{"query":"pragma","reqid":"1720238245587717-4938045162062945081-balancer-l7leveler-kubr-yp-sas-96-BAL","noreask":"1","lr":"21206","counters":{"type":"b","data":{"$header":"0_jookz000","logo":"0_jookz001","login":"0_jookz003","usermenu":"0_jookz004","market-cart":"0_jookz006","more-button":"0_jookz007","cbir":"0_jookz008","$navigation":"0_jookz009","item":"0_jookz00i","tab-www":"0_jookz00b","tab-images":"0_jookz00d","tab-video":"0_jookz00f","tab-maps":"0_jookz00h","tab-translate":"0_jookz00j"}}},"loggedIn":false,"baobab":{"parentNode":{"context":{"genInfo":{"prefix":"0_jookw01-0-1"},"ui":"desktop","service":"web","reqid":"1720238245587717-4938045162062945081-balancer-l7leveler-kubr-yp-sas-96-BAL","fast":{"name":"header-desktop"}}}}},"type":"header-desktop"},"2_jook0":{"state":{"answersUrl":"https://stackoverflow.com/questions/232785/use-of-pragma-in-c#answers","type":"fact","tabsOptions":[{"id":"question","text":"Soru"},{"id":"bestAnswer","text":"En iyi yanıt"},{"id":"moreAnswers","text":"9 yanıt daha","shortText":"Daha fazla"}],"tabContents":{"question":{"construct":[{"type":"paragraph","content":[{"type":"text","content":"What are some uses of "},{"type":"code","content":[{"type":"text","content":"#pragma"}],"isInline":true},{"type":"text","content":" in C, with examples?"}]}],"footerProps":{"date":1490457023,"numLiked":135,"numCommented":3}},"bestAnswer":{"construct":[{"type":"paragraph","content":[{"type":"code","content":[{"type":"text","content":"#pragma"}],"isInline":true},{"type":"text","content":" is for compiler directives that are machine-specific or operating-system-specific, i.e. it tells the compiler to do something, set some option, take some action, override some default, etc. that may or may not apply to all machines and operating systems."}]},{"type":"paragraph","content":[{"type":"text","content":"See "},{"type":"text","content":"msdn"},{"type":"text","content":" for more info."}]}],"footerProps":{"date":1490455723,"numLiked":77,"numCommented":1}},"moreAnswers":[{"construct":[{"type":"paragraph","content":[{"type":"code","content":[{"type":"text","content":"#pragma"}],"isInline":true},{"type":"text","content":" is used to do something implementation-specific in C, i.e. be pragmatic for the current context rather than ideologically dogmatic."}]},{"type":"paragraph","content":[{"type":"text","content":"The one I regularly use is "},{"type":"code","content":[{"type":"text","content":"#pragma pack(1)"}],"isInline":true},{"type":"text","content":" where I'm trying to squeeze more out of my memory space on embedded solutions, with arrays of structures that would otherwise end up with 8 byte alignment."}]},{"type":"paragraph","content":[{"type":"text","content":"Pity we don't have a "},{"type":"code","content":[{"type":"text","content":"#dogma"}],"isInline":true},{"type":"text","content":" yet. That would be fun ;)"}]}],"footerProps":{"date":1490455778,"numLiked":62,"numCommented":2}},{"construct":[{"type":"paragraph","content":[{"type":"text","content":"I would generally try to avoid the use of #pragmas if possible, since they're extremely compiler-dependent and non-portable. If you want to use them in a portable fashion, you'll have to surround every pragma with a "},{"type":"code","content":[{"type":"text","content":"#if"}],"isInline":true},{"type":"text","content":"/"},{"type":"code","content":[{"type":"text","content":"#endif"}],"isInline":true},{"type":"text","content":" pair. GCC discourages the use of pragmas, and really only supports some of them for compatibility with other compilers; GCC has other ways of doing the same things that other compilers use pragmas for."}]},{"type":"paragraph","content":[{"type":"text","content":"For example, here's how you'd ensure that a structure is packed tightly (i.e. no padding between members) in MSVC:"}]},{"type":"code","content":[{"type":"text","content":[{"type":"text","color":"comment","content":"#pragma pack(push, 1)"}]},{"type":"text","content":[{"type":"text","color":"keyword","content":"struct"},{"type":"text","content":" PackedStructure"}]},{"type":"text","content":[{"type":"text","content":"{"}]},{"type":"text","content":[{"type":"text","content":" "},{"type":"text","color":"name","content":"char"},{"type":"text","content":" a;"}]},{"type":"text","content":[{"type":"text","content":" "},{"type":"text","color":"name","content":"int"},{"type":"text","content":" b;"}]},{"type":"text","content":[{"type":"text","content":" "},{"type":"text","color":"name","content":"short"},{"type":"text","content":" c;"}]},{"type":"text","content":[{"type":"text","content":"};"}]},{"type":"text","content":[{"type":"text","color":"comment","content":"#pragma pack(pop)"}]},{"type":"text","content":[{"type":"text","color":"comment","content":"// sizeof(PackedStructure) == 7"}]}]},{"type":"paragraph","content":[{"type":"text","content":"Here's how you'd do the same thing in GCC:"}]},{"type":"code","content":[{"type":"text","content":[{"type":"text","color":"keyword","content":"struct"},{"type":"text","content":" PackedStructure __attribute__((__packed__))"}]},{"type":"text","content":[{"type":"text","content":"{"}]},{"type":"text","content":[{"type":"text","content":" "},{"type":"text","color":"name","content":"char"},{"type":"text","content":" a;"}]},{"type":"text","content":[{"type":"text","content":" "},{"type":"text","color":"name","content":"int"},{"type":"text","content":" b;"}]},{"type":"text","content":[{"type":"text","content":" "},{"type":"text","color":"name","content":"short"},{"type":"text","content":" c;"}]},{"type":"text","content":[{"type":"text","content":"};"}]},{"type":"text","content":[{"type":"text","color":"comment","content":"// sizeof(PackedStructure == 7)"}]}]},{"type":"paragraph","content":[{"type":"text","content":"The GCC code is more portable, because if you want to compile that with a non-GCC compiler, all you have to do is"}]},{"type":"paragraph","content":[{"type":"code","content":[{"type":"text","content":"#define __attribute__(x)"}],"isInline":true}]},{"type":"paragraph","content":[{"type":"text","content":"Whereas if you want to port the MSVC code, you have to surround each pragma with a "},{"type":"code","content":[{"type":"text","content":"#if"}],"isInline":true},{"type":"text","content":"/"},{"type":"code","content":[{"type":"text","content":"#endif"}],"isInline":true},{"type":"text","content":" pair. Not pretty."}]}],"footerProps":{"date":1537961811,"numLiked":43,"numCommented":5}}]},"organic":{"faviconProps":{"src":"https://favicon.yandex.net/favicon/v2/https://stackoverflow.com","size":"m","pageNumber":0,"index":0},"title":"Use of #\u0007[pragma\u0007] in C","pathProps":{"items":[{"url":"https://stackoverflow.com/questions/232785/use-of-pragma-in-c","text":"stackoverflow.com"},{"url":"https://stackoverflow.com/questions/232785/use-of-pragma-in-c","text":"use-of-pragma-in-c"}]},"faviconPosition":0,"subtitlePosition":1,"linkProps":{"url":"https://stackoverflow.com/questions/232785/use-of-pragma-in-c"},"hostTitle":"stackoverflow.com","description":""},"extralinksProps":{"hidden":true,"directions":["bottom-end"],"items":[{"variant":"reportFeedback","reportFeedback":{"feature":"Блок ответов для разработчиков","title":"Bu yanıtta yanlış olan nedir?","checkBoxLabels":[{"value":"Yanıt sorguya uygun değil"},{"value":"Yanıt hatalı"},{"value":"Yanıttaki bilgiler eksik"},{"value":"Diğer"}]}}]},"baobab":{"parentNode":{"context":{"genInfo":{"prefix":"2_jookw0c-0-1"},"ui":"desktop","service":"web","reqid":"1720238245587717-4938045162062945081-balancer-l7leveler-kubr-yp-sas-96-BAL","fast":{"name":"article"}}}}},"type":"article"},"2_jook1":{"state":{"linksGroups":[{"type":"geo","links":[{"label":"Columbus","title":"Columbus","url":"//yandex.com.tr/tune/geo","logNode":{"name":"region"},"target":"_self","a11yLabel":"Bölgeniz Columbus","needRetpath":true}]},{"type":"feedback","links":[{"label":"Hata bildir","logNode":{"name":"feedback","attrs":{"behaviour":{"type":"dynamic"}}}}]},{"type":"settings","links":[{"label":"Ayarlar","url":"//yandex.com.tr/tune/search","logNode":{"name":"settings"},"target":"_self","needRetpath":true}]},{"type":"company","links":[{"label":"Hakkımızda","url":"https://company.yandex.com.tr","logNode":{"name":"about"},"target":"_blank"},{"label":"Ticari teklifler","url":"/search/direct?text=pragma&filters_docs=direct_cm","logNode":{"name":"commercial"},"target":"_blank"},{"label":"Kariyer","url":"//yandex.com.tr/jobs/?utm_source=serp_turkie&utm_medium=footerlink&utm_content=career","logNode":{"name":"vacancy"},"target":"_blank"},{"label":"Kullanım lisansı","url":"//yandex.com.tr/legal/termsofuse/","logNode":{"name":"license"},"target":"_blank"},{"label":"Gizlilik Politikası","url":"//yandex.com.tr/legal/confidential/","logNode":{"name":"confidential"},"target":"_blank"}],"a11yHidden":true}],"reportFeedbackProps":{"feature":"Подвал","title":"Hata bildir","checkBoxLabels":[]},"isSearchApp":false,"hasExtralinks":true,"limitingSelector":".AliceFabButton","baobab":{"parentNode":{"context":{"genInfo":{"prefix":"2_jookw0d-0-1"},"ui":"desktop","service":"web","reqid":"1720238245587717-4938045162062945081-balancer-l7leveler-kubr-yp-sas-96-BAL"}}}},"type":"serp-footer"},"2_jook2":{"state":{"conditionLoadList":{"marketCart":false,"highchartsHighstock":false,"advProductGallery":false,"musicPlayer":false,"ecomRates":false,"photoViewer":false,"darkmodeChangeDrawer":true},"reportFeedbackBaseProps":{"initEmail":"","metaFields":{"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","userTestids":"186144,1047442,151171,287509,1048566,338390,1006734,1052098,1055738,1056680,1059347,1054350,1048636,1039609,1017727,1051463,1052893","yandexuid":"3693766611720238218","uid":"0","queryText":"pragma","reqid":"1720238245587717-4938045162062945081-balancer-l7leveler-kubr-yp-sas-96-BAL","searchSlices":["drawer_search_slice_ecom","drawer_search_slice_english","drawer_search_slice_cs"],"userRegionName":"Columbus","userRegionId":"20815"}},"extralinksPopupProps":{"abuseLink":"https://twitter.yandex.com.tr/search/abuse?sign=ed696a3f4842b26a59c42252fcab2e25&keyno=0"},"isLoggedIn":false,"userMenuDialogProps":{"flag":"skin,feedback","host":"yandex.com.tr","lang":"tr","project":"serp","queryParams":{"utm_source":"search"},"retpath":"https%3A%2F%2Ftwitter.yandex.com.tr%2Fsearch%2F%3Fes_context%3D0oYl8Q____________ARpLMTcxOTQyNzg1NjM0NDcyNC0yNTI3NzQ4MDU1OTQ3NjIxMTg2LWJhbGFuY2VyLWw3bGV2ZWxlci1rdWJyLXlwLWtsZy0zMDgtQkFMMgVhc3NvY9J9Wpk%26lr%3D21206%26noreask%3D1%26p%3D0%26rq%3D1%26serp-reload-from%3Drec_bottom%26text%3Dpragma%26ncrnd%3D81209","tld":"com.tr"},"baobab":{"parentNode":{"context":{"genInfo":{"prefix":"2_jookw0e-0-1"},"ui":"desktop","service":"web","reqid":"1720238245587717-4938045162062945081-balancer-l7leveler-kubr-yp-sas-96-BAL","fast":{"name":"lazy-load"}}}}},"type":"lazy-load"}}