Sémantique en ligne c99 avec gcc (mspgcc)

J’écris quelques fonctions que je voudrais intégrer.

Lire ici et utiliser la deuxième option inline c99 avec inline sur toutes les déclarations et définitions, comme ceci:

extern inline void SPFD54124B_write_cmd(uint16_t command); 

dans un en-tête, et

 inline void SPFD54124B_write_cmd(uint16_t command) { spi_write(command, CMD_WIDTH); } 

dans un fichier c correspondant. Je m’attendais à obtenir des versions en ligne des fonctions.

Mais quand je comstack je reçois:

 Generating dependencies dep/spi.d from src/spi.c Generating dependencies dep/spfd54124b.d from src/spfd54124b.c Generating dependencies dep/pomodoro.d from src/pomodoro.c Generating dependencies dep/font8x8_ualnum.d from src/font8x8_ualnum.c Generating dependencies dep/font8x8_basic.d from src/font8x8_basic.c Generating dependencies dep/evading_util.d from src/evading_util.c Compiling src/evading_util.c Compiling src/font8x8_basic.c Compiling src/font8x8_ualnum.c Compiling src/pomodoro.c src/spfd54124b.h:96:20: warning: inline function 'SPFD54124B_write_pixel' declared but never defined [enabled by default] src/spfd54124b.h:95:20: warning: inline function 'SPFD54124B_write_param' declared but never defined [enabled by default] src/spfd54124b.h:94:20: warning: inline function 'SPFD54124B_write_cmd' declared but never defined [enabled by default] src/spi.h:22:20: warning: inline function 'spi_write' declared but never defined [enabled by default] src/spfd54124b.h:96:20: warning: inline function 'SPFD54124B_write_pixel' declared but never defined [enabled by default] src/spfd54124b.h:95:20: warning: inline function 'SPFD54124B_write_param' declared but never defined [enabled by default] src/spfd54124b.h:94:20: warning: inline function 'SPFD54124B_write_cmd' declared but never defined [enabled by default] src/spi.h:22:20: warning: inline function 'spi_write' declared but never defined [enabled by default] src/pomodoro.c: In function 'main': src/spfd54124b.h:94:20: warning: inlining failed in call to 'SPFD54124B_write_cmd': function body not available [-Winline] src/pomodoro.c:29:25: warning: called from here [-Winline] src/spfd54124b.h:94:20: warning: inlining failed in call to 'SPFD54124B_write_cmd': function body not available [-Winline] src/pomodoro.c:31:25: warning: called from here [-Winline] src/spfd54124b.h:94:20: warning: inlining failed in call to 'SPFD54124B_write_cmd': function body not available [-Winline] src/pomodoro.c:35:25: warning: called from here [-Winline] src/spfd54124b.h:94:20: warning: inlining failed in call to 'SPFD54124B_write_cmd': function body not available [-Winline] src/pomodoro.c:36:25: warning: called from here [-Winline] src/spfd54124b.h:96:20: warning: inlining failed in call to 'SPFD54124B_write_pixel': function body not available [-Winline] src/pomodoro.c:40:31: warning: called from here [-Winline] src/spfd54124b.h:94:20: warning: inlining failed in call to 'SPFD54124B_write_cmd': function body not available [-Winline] src/pomodoro.c:43:25: warning: called from here [-Winline] Compiling src/spfd54124b.c src/spi.h:22:20: warning: inline function 'spi_write' declared but never defined [enabled by default] src/spi.h:22:20: warning: inline function 'spi_write' declared but never defined [enabled by default] src/spfd54124b.c: In function 'SPFD54124B_init': src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:124:14: warning: called from here [-Winline] src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:129:14: warning: called from here [-Winline] src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:124:14: warning: called from here [-Winline] src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:129:14: warning: called from here [-Winline] src/spfd54124b.c: In function 'SPFD54124B_read': src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:25:14: warning: called from here [-Winline] src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:29:14: warning: called from here [-Winline] src/spfd54124b.c: In function 'SPFD54124B_write_cmd': src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:124:14: warning: called from here [-Winline] src/spfd54124b.c: In function 'SPFD54124B_write_param': src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:129:14: warning: called from here [-Winline] src/spfd54124b.c: In function 'SPFD54124B_write_pixel': src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:129:14: warning: called from here [-Winline] src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:129:14: warning: called from here [-Winline] src/spfd54124b.c: In function 'SPFD54124B_setrow': src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:124:14: warning: called from here [-Winline] src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:129:14: warning: called from here [-Winline] src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:129:14: warning: called from here [-Winline] src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:129:14: warning: called from here [-Winline] src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:129:14: warning: called from here [-Winline] src/spfd54124b.c: In function 'SPFD54124B_setcol': src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:124:14: warning: called from here [-Winline] src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:129:14: warning: called from here [-Winline] src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:129:14: warning: called from here [-Winline] src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:129:14: warning: called from here [-Winline] src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:129:14: warning: called from here [-Winline] src/spfd54124b.c: In function 'SPFD54124B_lputch': src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:124:14: warning: called from here [-Winline] src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:129:14: warning: called from here [-Winline] src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:129:14: warning: called from here [-Winline] src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:129:14: warning: called from here [-Winline] src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:129:14: warning: called from here [-Winline] src/spfd54124b.c: In function 'SPFD54124B_putch': src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:124:14: warning: called from here [-Winline] src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:129:14: warning: called from here [-Winline] src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:129:14: warning: called from here [-Winline] src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:129:14: warning: called from here [-Winline] src/spi.h:22:20: warning: inlining failed in call to 'spi_write': function body not available [-Winline] src/spfd54124b.c:129:14: warning: called from here [-Winline] Compiling src/spi.c Linking bin/pomodoro.elf >>>> Size of Firmware <<<< text data bss dec hex filename 3150 0 2 3152 c50 bin/pomodoro.elf src/spfd54124b.h:96:20: warning: inline function 'SPFD54124B_write_pixel' declared but never defined [enabled by default] src/spfd54124b.h:95:20: warning: inline function 'SPFD54124B_write_param' declared but never defined [enabled by default] src/spfd54124b.h:94:20: warning: inline function 'SPFD54124B_write_cmd' declared but never defined [enabled by default] src/spi.h:22:20: warning: inline function 'spi_write' declared but never defined [enabled by default] src/spfd54124b.h:96:20: warning: inline function 'SPFD54124B_write_pixel' declared but never defined [enabled by default] src/spfd54124b.h:95:20: warning: inline function 'SPFD54124B_write_param' declared but never defined [enabled by default] src/spfd54124b.h:94:20: warning: inline function 'SPFD54124B_write_cmd' declared but never defined [enabled by default] src/spi.h:22:20: warning: inline function 'spi_write' declared but never defined [enabled by default] src/pomodoro.c: In function 'main': src/spfd54124b.h:94:20: warning: inlining failed in call to 'SPFD54124B_write_cmd': function body not available [-Winline] src/pomodoro.c:29:25: warning: called from here [-Winline] src/spfd54124b.h:94:20: warning: inlining failed in call to 'SPFD54124B_write_cmd': function body not available [-Winline] src/pomodoro.c:31:25: warning: called from here [-Winline] src/spfd54124b.h:94:20: warning: inlining failed in call to 'SPFD54124B_write_cmd': function body not available [-Winline] src/pomodoro.c:35:25: warning: called from here [-Winline] src/spfd54124b.h:94:20: warning: inlining failed in call to 'SPFD54124B_write_cmd': function body not available [-Winline] src/pomodoro.c:36:25: warning: called from here [-Winline] src/spfd54124b.h:96:20: warning: inlining failed in call to 'SPFD54124B_write_pixel': function body not available [-Winline] src/pomodoro.c:40:31: warning: called from here [-Winline] src/spfd54124b.h:94:20: warning: inlining failed in call to 'SPFD54124B_write_cmd': function body not available [-Winline] src/pomodoro.c:43:25: warning: called from here [-Winline] 

Je ne suis pas sûr de comprendre les différentes alternatives en ligne de c99.

Vous avez des choses exactement dans le mauvais sens de la façon dont vous en avez besoin. Dans l’en-tête, vous devriez utiliser:

 inline void SPFD54124B_write_cmd(uint16_t command) { spi_write(command, CMD_WIDTH); } 

Dans les unités de traduction qui incluent cet en-tête, cela créera une fonction en ligne avec une liaison externe. Dans exactement l’ une de ces unités de traduction, vous devez également placer la déclaration:

 extern void SPFD54124B_write_cmd(uint16_t); 

Ceci (avec la définition inline de l’en-tête) créera une définition externe de la fonction. Les autres fichiers qui incluent l’en-tête mais pas la déclaration extern créeront une définition en ligne de la fonction: une définition uniquement disponible dans cette unité de traduction, mais qui n’interdit pas une définition externe ailleurs.

Au total, vous aurez une définition externe de la fonction, et chaque fichier qui inclut l’en-tête aura également une définition non-externe disponible; le compilateur peut utiliser soit. Conceptuellement, il ne rest qu’une seule fonction appelée SPFD54124B_write_cmd dans le programme complet – par exemple, si vous prenez l’adresse de la fonction dans plusieurs unités de traduction, vous devriez obtenir la même valeur.

Au lieu de cela, vous pouvez mettre ceci dans l’en-tête:

 static inline void SPFD54124B_write_cmd(uint16_t command) { spi_write(command, CMD_WIDTH); } 

et n’utilisez aucune déclaration extern du tout; cela créera une fonction en ligne avec une liaison interne dans chaque fichier incluant l’en-tête. Il n’y aura aucune définition externe de la fonction, et conceptuellement, chaque unité de traduction qui inclut l’en-tête possède sa propre copie indépendante de la fonction.


(Il convient de noter pour la postérité que le mode par défaut actuel de GCC est “gnu89”, qui n’implémente pas la sémantique C99 pour inline )

Pour s’assurer qu’une fonction peut être en ligne ACTUELLEMENT, elle doit être définie dans le fichier d’en-tête.

Lorsque vous ne le faites pas, la plupart des compilateurs n’intègrent pas réellement la fonction.

Donc, ma suggestion serait de déplacer le contenu de la fonction réelle dans le fichier d’en-tête:

 inline void SPFD54124B_write_cmd(uint16_t command) { spi_write(command, CMD_WIDTH); }