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/10/17 17:03] – Détail de l'archive 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::list< | + | Rendu : |
| - | f(c); | + | |
| - | f({" | + | {{gh>https:// |
| - | 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.1571324606.txt.gz · Dernière modification : de root
