Domanda

#define VERSION 1U

#define _VALUE_TO_STRING(x) #x
#define VALUE_TO_STRING(var) _VALUE_TO_STRING(var)

#define VERSION_STRING VALUE_TO_STRING(VERSION)

char readMe[] = "The current version of this document is " VERSION_STRING ".";
.

...

Ho questa parte del codice in cui ho bisogno di una stringa globale (readme) da creare al tempo di inizializzazione. L'output del codice sopra riportato sarà -> La versione corrente di questo documento è 1U. Quindi quello che voglio è sbarazzarsi di quella "u". C'è una possibilità che risolvo questo con le funzioni di preprocessore? (Mi piace trasformare il valore definito senza segno su un valore definito firmato ...)?

È stato utile?

Soluzione

Non penso che ci sia un metodo pre-processore per estrarre il U da VERSION.Tuttavia, puoi combinarli.Suggerirei:

#define UNSIGNED_VERSION 1

#define VERSION UNSIGNED_VERSION ## U

#define _VALUE_TO_STRING(x) #x
#define VALUE_TO_STRING(var) _VALUE_TO_STRING(var)

#define VERSION_STRING VALUE_TO_STRING(UNSIGNED_VERSION)

char readMe[] = "The current version of this document is " VERSION_STRING ".";
.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top