{"id":2521,"date":"2025-07-17T10:15:12","date_gmt":"2025-07-17T09:15:12","guid":{"rendered":"https:\/\/workboot.fr\/ciela\/?page_id=2521"},"modified":"2025-07-17T10:15:57","modified_gmt":"2025-07-17T09:15:57","slug":"macro-define","status":"publish","type":"page","link":"https:\/\/workboot.fr\/ciela\/macro-define\/","title":{"rendered":"macro , #define"},"content":{"rendered":"\n<nav aria-label=\"Table des mati\u00e8res\" class=\"wp-block-table-of-contents\"><ol><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/macro-define\/#1-qu-est-ce-que-define\">1. Qu\u2019est-ce que #define ?<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/macro-define\/#syntaxe-basique\">Syntaxe basique<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/macro-define\/#exemple-simple-constantes\">Exemple simple : constantes<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/macro-define\/#formules-a-substituer\">Formules \u00e0 substituer <\/a><ol><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/macro-define\/#resume-rapide\">R\u00e9sum\u00e9 rapide<\/a><\/li><\/ol><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/macro-define\/#pre-compilateur\">Pr\u00e9 compilateur <\/a><ol><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/macro-define\/#autre-facon-d-arreter-a-la-precompilation\">autre fa\u00e7on d\u2019arr\u00eater \u00e0 la pr\u00e9compilation<\/a><\/li><\/ol><\/li><\/ol><\/nav>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"1-qu-est-ce-que-define\">1. Qu\u2019est-ce que <code>#define<\/code> ?<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>#define<\/code> est une <strong>directive du pr\u00e9processeur C<\/strong>.<\/li>\n\n\n\n<li>Elle sert \u00e0 <strong>d\u00e9finir des constantes ou des macros<\/strong> avant la compilation.<\/li>\n\n\n\n<li>Le pr\u00e9processeur remplace <strong>toutes les occurrences<\/strong> du nom d\u00e9fini par la valeur correspondante dans le code.<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"syntaxe-basique\">Syntaxe basique<\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>#define NOM valeur<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>NOM<\/code> est le nom que tu choisis (souvent en majuscules pour les constantes).<\/li>\n\n\n\n<li><code>valeur<\/code> peut \u00eatre un nombre, un texte, une expression, voire du code.<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"exemple-simple-constantes\">Exemple simple : constantes<\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>#define PI 3.14159\n#define MAX 100\n#define ON 1\n#define OFF 0<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"formules-a-substituer\">Formules \u00e0 substituer <\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>#define SQUARE(x) ((x) * (x))<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">exemple d&rsquo;utilisation:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int a = 5;\nint b = SQUARE(a);  \/\/ \u00e9quivaut \u00e0 5*5 = 25<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Exemple complet <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h>\n\n#define ON 1\n#define OFF 0\n#define SQUARE(x) ((x) * (x))\n\nint main() {\n    int etat = ON;\n\n    if (etat == ON) {\n        printf(\"Allum\u00e9\\n\");\n    } else {\n        printf(\"\u00c9teint\\n\");\n    }\n\n    int val = 4;\n    printf(\"Carr\u00e9 de %d = %d\\n\", val, SQUARE(val));\n\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"resume-rapide\">R\u00e9sum\u00e9 rapide<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u00c9l\u00e9ment<\/th><th>R\u00f4le<\/th><th>Exemple<\/th><\/tr><\/thead><tbody><tr><td><code>#define<\/code><\/td><td>Remplacement texte<\/td><td><code>#define PI 3.14<\/code><\/td><\/tr><tr><td>Constante<\/td><td>Valeur fixe<\/td><td><code>#define MAX 100<\/code><\/td><\/tr><tr><td>Macro fonction<\/td><td>Macro avec param\u00e8tres<\/td><td><code>#define MUL(x,y) ((x)*(y))<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"pre-compilateur\">Pr\u00e9 compilateur <\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h>\n#define PI 3.14\n\nint main() {\n    printf(\"Pi = %f\\n\", PI);\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">on voit la substitution <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>etudiant@ordi:~\/Works\/TP3_C\/precomp$ vi precomp.c\netudiant@ordi:~\/Works\/TP3_C\/precomp$ gcc precomp.c -E\n# 0 \"precomp.c\"\n# 0 \"&lt;built-in>\"\n# 0 \"&lt;command-line>\"\n# 1 \"\/usr\/include\/stdc-predef.h\" 1 3 4\n# 0 \"&lt;command-line>\" 2\n# 1 \"precomp.c\"\nnclude &lt;stdio.h>\n\n\nint main() {\n    printf(\"Pi = %f\\n\", <mark style=\"background-color:rgba(0, 0, 0, 0);color:#cf2e2e\" class=\"has-inline-color\">3.14<\/mark>);\n    return 0;\n}\netudiant@ordi:~\/Works\/TP3_C\/precomp$ \n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"autre-facon-d-arreter-a-la-precompilation\">autre fa\u00e7on d\u2019arr\u00eater \u00e0 la pr\u00e9compilation<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>etudiant@ordi:~\/Works\/TP3_C\/precomp$ gcc -E precomp.c -o precomp.i\netudiant@ordi:~\/Works\/TP3_C\/precomp$ cat precomp.i\n# 0 \"precomp.c\"\n# 0 \"&lt;built-in>\"\n# 0 \"&lt;command-line>\"\n# 1 \"\/usr\/include\/stdc-predef.h\" 1 3 4\n# 0 \"&lt;command-line>\" 2\n# 1 \"precomp.c\"\nnclude &lt;stdio.h>\n\n\nint main() {\n    printf(\"Pi = %f\\n\", 3.14);\n    return 0;\n}\netudiant@ordi:~\/Works\/TP3_C\/precomp$ \n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1. Qu\u2019est-ce que #define ? Syntaxe basique Exemple simple : constantes Formules \u00e0 substituer exemple d&rsquo;utilisation: Exemple complet R\u00e9sum\u00e9 rapide \u00c9l\u00e9ment R\u00f4le Exemple #define Remplacement texte #define PI 3.14 Constante [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","_uag_custom_page_level_css":"","footnotes":""},"class_list":["post-2521","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>macro , #define - workboot<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/workboot.fr\/ciela\/macro-define\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"macro , #define - workboot\" \/>\n<meta property=\"og:description\" content=\"1. Qu\u2019est-ce que #define ? Syntaxe basique Exemple simple : constantes Formules \u00e0 substituer exemple d&rsquo;utilisation: Exemple complet R\u00e9sum\u00e9 rapide \u00c9l\u00e9ment R\u00f4le Exemple #define Remplacement texte #define PI 3.14 Constante [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/workboot.fr\/ciela\/macro-define\/\" \/>\n<meta property=\"og:site_name\" content=\"workboot\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-17T09:15:57+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Dur\u00e9e de lecture estim\u00e9e\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/macro-define\\\/\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/macro-define\\\/\",\"name\":\"macro , #define - workboot\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#website\"},\"datePublished\":\"2025-07-17T09:15:12+00:00\",\"dateModified\":\"2025-07-17T09:15:57+00:00\",\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/workboot.fr\\\/ciela\\\/macro-define\\\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#website\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/\",\"name\":\"workboot\",\"description\":\"Open Source, Open Minds \",\"publisher\":{\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fr-FR\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#organization\",\"name\":\"workboot\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/logo_ciel-dorian-1.png\",\"contentUrl\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/logo_ciel-dorian-1.png\",\"width\":1024,\"height\":950,\"caption\":\"workboot\"},\"image\":{\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#\\\/schema\\\/logo\\\/image\\\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"macro , #define - workboot","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/workboot.fr\/ciela\/macro-define\/","og_locale":"fr_FR","og_type":"article","og_title":"macro , #define - workboot","og_description":"1. Qu\u2019est-ce que #define ? Syntaxe basique Exemple simple : constantes Formules \u00e0 substituer exemple d&rsquo;utilisation: Exemple complet R\u00e9sum\u00e9 rapide \u00c9l\u00e9ment R\u00f4le Exemple #define Remplacement texte #define PI 3.14 Constante [&hellip;]","og_url":"https:\/\/workboot.fr\/ciela\/macro-define\/","og_site_name":"workboot","article_modified_time":"2025-07-17T09:15:57+00:00","twitter_misc":{"Dur\u00e9e de lecture estim\u00e9e":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/workboot.fr\/ciela\/macro-define\/","url":"https:\/\/workboot.fr\/ciela\/macro-define\/","name":"macro , #define - workboot","isPartOf":{"@id":"https:\/\/workboot.fr\/ciela\/#website"},"datePublished":"2025-07-17T09:15:12+00:00","dateModified":"2025-07-17T09:15:57+00:00","inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/workboot.fr\/ciela\/macro-define\/"]}]},{"@type":"WebSite","@id":"https:\/\/workboot.fr\/ciela\/#website","url":"https:\/\/workboot.fr\/ciela\/","name":"workboot","description":"Open Source, Open Minds ","publisher":{"@id":"https:\/\/workboot.fr\/ciela\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/workboot.fr\/ciela\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fr-FR"},{"@type":"Organization","@id":"https:\/\/workboot.fr\/ciela\/#organization","name":"workboot","url":"https:\/\/workboot.fr\/ciela\/","logo":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/workboot.fr\/ciela\/#\/schema\/logo\/image\/","url":"https:\/\/workboot.fr\/ciela\/wp-content\/uploads\/2025\/05\/logo_ciel-dorian-1.png","contentUrl":"https:\/\/workboot.fr\/ciela\/wp-content\/uploads\/2025\/05\/logo_ciel-dorian-1.png","width":1024,"height":950,"caption":"workboot"},"image":{"@id":"https:\/\/workboot.fr\/ciela\/#\/schema\/logo\/image\/"}}]}},"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"admin","author_link":"https:\/\/workboot.fr\/ciela\/author\/admin\/"},"uagb_comment_info":0,"uagb_excerpt":"1. Qu\u2019est-ce que #define ? Syntaxe basique Exemple simple : constantes Formules \u00e0 substituer exemple d&rsquo;utilisation: Exemple complet R\u00e9sum\u00e9 rapide \u00c9l\u00e9ment R\u00f4le Exemple #define Remplacement texte #define PI 3.14 Constante [&hellip;]","_links":{"self":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/2521","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/comments?post=2521"}],"version-history":[{"count":2,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/2521\/revisions"}],"predecessor-version":[{"id":2524,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/2521\/revisions\/2524"}],"wp:attachment":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/media?parent=2521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}