lang:cpp:preprocesseur
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
lang:cpp:preprocesseur [2019/12/18 23:04] – Ajout des mauvais exemples root | lang:cpp:preprocesseur [2022/08/18 10:31] (Version actuelle) – [Désactiver certains warnings pour certains compilateurs] : déplacement côté C root | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ===Utiliser les std:: | ||
- | Le préprocesseur a du mal avec les '' | ||
- | <code cpp> | + | ===Utiliser les std:: |
- | void f(std:: | + | Le préprocesseur, |
- | #define F(XXXX) f(XXXX) | + | |
- | int main() | + | {{gh> |
- | { | + | |
- | std:: | + | Rendu : |
- | f(c); | + | |
- | f({" | + | {{gh>https://github.com/bansan85/wiki_le_garrec_fr_travis/blob/master/cpp/preprocessor/bracket.cpp.i -13}} |
- | F((std:: | + | |
- | F(std:: | + | On voit bien que le préprocesseur respecte les parenthèses mais pas les crochets. |
- | | + | |
- | | + | |
- | } | + | |
- | </ | + | |
[[https:// | [[https:// | ||
+ | |||
+ | ===Remplacer les #define par #pragma once=== | ||
+ | |||
+ | On peut lancer le script python suivant. | ||
+ | |||
+ | Il remplace le premier ''# | ||
+ | |||
+ | La méthode n'est pas parfaite. Elle peut poser des problèmes sur les fichiers n' | ||
+ | |||
+ | <file python remove_header.py> | ||
+ | import re | ||
+ | from pathlib import Path | ||
+ | |||
+ | def my_function(fname): | ||
+ | with open(fname, ' | ||
+ | lines = infile.readlines() | ||
+ | |||
+ | pifn = re.compile(' | ||
+ | pdefinc = re.compile(' | ||
+ | pendif = re.compile(' | ||
+ | i = len(lines)-2 | ||
+ | for i in range(len(lines)-1): | ||
+ | if lines[i] == '# | ||
+ | return | ||
+ | if pifn.search(lines[i]) and pdefinc.search(lines[i+1]): | ||
+ | break | ||
+ | | ||
+ | if i != len(lines)-2: | ||
+ | print(i, lines[i]) | ||
+ | lines[i] = "# | ||
+ | del lines[i+1] | ||
+ | | ||
+ | for i in range(len(lines)-1, | ||
+ | if pendif.search(lines[i]): | ||
+ | print(i, lines[i]) | ||
+ | del lines[i] | ||
+ | if lines[i-1]==" | ||
+ | del lines[i] | ||
+ | with open(fname, ' | ||
+ | outfile.write('' | ||
+ | break | ||
+ | |||
+ | |||
+ | for path in Path(' | ||
+ | try: | ||
+ | my_function(path) | ||
+ | except UnicodeDecodeError: | ||
+ | pass | ||
+ | except PermissionError: | ||
+ | pass | ||
+ | </ |
lang/cpp/preprocesseur.1576706671.txt.gz · Dernière modification : 2019/12/18 23:04 de root