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 [2020/07/08 10:57] – Code -> gh 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:: | ===Utiliser les std:: | ||
Le préprocesseur, | Le préprocesseur, | ||
Ligne 11: | Ligne 12: | ||
[[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.1594198623.txt.gz · Dernière modification : 2020/07/08 10:57 de root