Si el archivo de cabecera incluido se expande en el archivo C

Un registro de mis problemas

utiliza el siguiente procedimiento C muy simple. Lo que entiendo es que primero se llama precoder para extender macros y archivos de cabecera, etc.
Entiendo que el precodificador contendrá primero todo el Código (declaración) en el archivo de cabecera stdio. Antes de compilar, a ñadir H al archivo C, haciendo que el archivo C sea más grande y con diferentes números de línea, por lo que la llamada printf () estará más abajo en el archivo.
¿En caso afirmativo, por qué los números de línea siguen siendo correctos durante la depuración?
#include <stdio.h>
int main()
{
    printf("Hello world!\n");
}

Estrategia óptima de procesamiento

sí, el contenido del archivo de cabecera está incluido en el texto.
Los números de línea se mantienen porque el preprocesador tiene un mecanismo que apunta a specify the line numbers:
#line 97 "original.c"
/* This is line 97 of the original C file */
Estos números de línea se utilizan para reportar errores. Por lo general, el compilador utiliza una notación abreviada que puede entender - generalmente omite la palabra line y a ñade información adicional - ver, por ejemplo, GCC Preprocessor output.
Se puede ver compilando
#line 1000
pod variable = { 0 };
Archivarlo; Intenta compilarlo; Tenga en cuenta que el compilador se queja del tipo desconocido pod en la línea 1000, incluso si es la línea 2 en el archivo fuente.
$ gcc -O -c original.c
original.c:1000:1: error: unknown type name ‘pod’
$
Puede ejecutar el preprocesador y ver (gran) la salida en GCC y la mayoría de los compiladores C basados en UNIX usando la opción -E:
$ gcc -E original.c
# 1 "original.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "original.c"
# 1000 "original.c"
pod variable = { 0 };
$
Tenga en cuenta que si incluyo <stdio.h>, la salida será mucho mayor (tengo 577 líneas en una máquina - Esto es menos de lo que esperaba).
También puede utilizar algunos de los parámetros del compilador C para ejecutar un preprocesador C independiente (comúnmente conocido como cpp). Esto a veces le da un resultado ligeramente diferente del editor en Jefe, pero a menudo es una buena manera de entender la situación.
Ahora, algo de mi código está mal - mi caso de prueba es:
/* Minimized GCC bug */

#include <assert.h>
#include <string.h>

extern int chk_arg(const char *arg);

int chk_arg(const char *arg)
{
    assert(strncmp(arg, "-", 1) == 0 && strncmp(arg, "--", 2) != 0);
    return (arg[1] == 'a');
}
Los errores de compilación que me molestan son:
$   gcc -std=c11 -Wall -Wmissing-prototypes -Wstrict-prototypes -Wextra -pedantic -Werror -g -O3   -c gccbug.c
gccbug.c: In function ‘chk_arg’:
gccbug.c:10:5: error: string length ‘4587’ is greater than the length ‘4095’ ISO C99 compilers are required to support [-Werror=overlength-strings]
   10 |     assert(strncmp(arg, "-", 1) == 0 && strncmp(arg, "--", 2) != 0);
      |     ^~~~~~
cc1: all warnings being treated as errors
$
No está claro dónde está la cadena de 4.587 caracteres antes de usar gcc -E:
int chk_arg(const char *arg)
{

# 10 "gccbug.c" 3 4
   (((__extension__ (__builtin_constant_p (
# 10 "gccbug.c"
   1
# 10 "gccbug.c" 3 4
   ) && ((__builtin_constant_p (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ) && strlen (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ) < ((size_t) (
# 10 "gccbug.c"
   1
# 10 "gccbug.c" 3 4
   ))) || (__builtin_constant_p (
# 10 "gccbug.c"
   "-"
# 10 "gccbug.c" 3 4
   ) && strlen (
# 10 "gccbug.c"
   "-"
# 10 "gccbug.c" 3 4
   ) < ((size_t) (
# 10 "gccbug.c"
   1
# 10 "gccbug.c" 3 4
   )))) ? __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ) && __builtin_constant_p (
# 10 "gccbug.c"
   "-"
# 10 "gccbug.c" 3 4
   ) && (__s1_len = strlen (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ), __s2_len = strlen (
# 10 "gccbug.c"
   "-"
# 10 "gccbug.c" 3 4
   ), (!((size_t)(const void *)((
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ) + 1) - (size_t)(const void *)(
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((
# 10 "gccbug.c"
   "-"
# 10 "gccbug.c" 3 4
   ) + 1) - (size_t)(const void *)(
# 10 "gccbug.c"
   "-"
# 10 "gccbug.c" 3 4
   ) == 1) || __s2_len >= 4)) ? __builtin_strcmp (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   , 
# 10 "gccbug.c"
   "-"
# 10 "gccbug.c" 3 4
   ) : (__builtin_constant_p (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ) && ((size_t)(const void *)((
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ) + 1) - (size_t)(const void *)(
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ) == 1) && (__s1_len = strlen (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ), __s1_len < 4) ? (__builtin_constant_p (
# 10 "gccbug.c"
   "-"
# 10 "gccbug.c" 3 4
   ) && ((size_t)(const void *)((
# 10 "gccbug.c"
   "-"
# 10 "gccbug.c" 3 4
   ) + 1) - (size_t)(const void *)(
# 10 "gccbug.c"
   "-"
# 10 "gccbug.c" 3 4
   ) == 1) ? __builtin_strcmp (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   , 
# 10 "gccbug.c"
   "-"
# 10 "gccbug.c" 3 4
   ) : (__extension__ ({ __const unsigned char *__s2 = (__const unsigned char *) (__const char *) (
# 10 "gccbug.c"
   "-"
# 10 "gccbug.c" 3 4
   ); register int __result = (((__const unsigned char *) (__const char *) (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((__const unsigned char *) (__const char *) (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((__const unsigned char *) (__const char *) (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((__const unsigned char *) (__const char *) (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (
# 10 "gccbug.c"
   "-"
# 10 "gccbug.c" 3 4
   ) && ((size_t)(const void *)((
# 10 "gccbug.c"
   "-"
# 10 "gccbug.c" 3 4
   ) + 1) - (size_t)(const void *)(
# 10 "gccbug.c"
   "-"
# 10 "gccbug.c" 3 4
   ) == 1) && (__s2_len = strlen (
# 10 "gccbug.c"
   "-"
# 10 "gccbug.c" 3 4
   ), __s2_len < 4) ? (__builtin_constant_p (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ) && ((size_t)(const void *)((
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ) + 1) - (size_t)(const void *)(
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ) == 1) ? __builtin_strcmp (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   , 
# 10 "gccbug.c"
   "-"
# 10 "gccbug.c" 3 4
   ) : (__extension__ ({ __const unsigned char *__s1 = (__const unsigned char *) (__const char *) (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ); register int __result = __s1[0] - ((__const unsigned char *) (__const char *) (
# 10 "gccbug.c"
   "-"
# 10 "gccbug.c" 3 4
   ))[0]; if (__s2_len > 0 && __result == 0) { __result = (__s1[1] - ((__const unsigned char *) (__const char *) (
# 10 "gccbug.c"
   "-"
# 10 "gccbug.c" 3 4
   ))[1]); if (__s2_len > 1 && __result == 0) { __result = (__s1[2] - ((__const unsigned char *) (__const char *) (
# 10 "gccbug.c"
   "-"
# 10 "gccbug.c" 3 4
   ))[2]); if (__s2_len > 2 && __result == 0) __result = (__s1[3] - ((__const unsigned char *) (__const char *) (
# 10 "gccbug.c"
   "-"
# 10 "gccbug.c" 3 4
   ))[3]); } } __result; }))) : __builtin_strcmp (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   , 
# 10 "gccbug.c"
   "-"
# 10 "gccbug.c" 3 4
   )))); }) : strncmp (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   , 
# 10 "gccbug.c"
   "-"
# 10 "gccbug.c" 3 4
   , 
# 10 "gccbug.c"
   1
# 10 "gccbug.c" 3 4
   ))) 
# 10 "gccbug.c"
   == 0 && 
# 10 "gccbug.c" 3 4
   (__extension__ (__builtin_constant_p (
# 10 "gccbug.c"
   2
# 10 "gccbug.c" 3 4
   ) && ((__builtin_constant_p (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ) && strlen (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ) < ((size_t) (
# 10 "gccbug.c"
   2
# 10 "gccbug.c" 3 4
   ))) || (__builtin_constant_p (
# 10 "gccbug.c"
   "--"
# 10 "gccbug.c" 3 4
   ) && strlen (
# 10 "gccbug.c"
   "--"
# 10 "gccbug.c" 3 4
   ) < ((size_t) (
# 10 "gccbug.c"
   2
# 10 "gccbug.c" 3 4
   )))) ? __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ) && __builtin_constant_p (
# 10 "gccbug.c"
   "--"
# 10 "gccbug.c" 3 4
   ) && (__s1_len = strlen (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ), __s2_len = strlen (
# 10 "gccbug.c"
   "--"
# 10 "gccbug.c" 3 4
   ), (!((size_t)(const void *)((
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ) + 1) - (size_t)(const void *)(
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((
# 10 "gccbug.c"
   "--"
# 10 "gccbug.c" 3 4
   ) + 1) - (size_t)(const void *)(
# 10 "gccbug.c"
   "--"
# 10 "gccbug.c" 3 4
   ) == 1) || __s2_len >= 4)) ? __builtin_strcmp (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   , 
# 10 "gccbug.c"
   "--"
# 10 "gccbug.c" 3 4
   ) : (__builtin_constant_p (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ) && ((size_t)(const void *)((
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ) + 1) - (size_t)(const void *)(
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ) == 1) && (__s1_len = strlen (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ), __s1_len < 4) ? (__builtin_constant_p (
# 10 "gccbug.c"
   "--"
# 10 "gccbug.c" 3 4
   ) && ((size_t)(const void *)((
# 10 "gccbug.c"
   "--"
# 10 "gccbug.c" 3 4
   ) + 1) - (size_t)(const void *)(
# 10 "gccbug.c"
   "--"
# 10 "gccbug.c" 3 4
   ) == 1) ? __builtin_strcmp (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   , 
# 10 "gccbug.c"
   "--"
# 10 "gccbug.c" 3 4
   ) : (__extension__ ({ __const unsigned char *__s2 = (__const unsigned char *) (__const char *) (
# 10 "gccbug.c"
   "--"
# 10 "gccbug.c" 3 4
   ); register int __result = (((__const unsigned char *) (__const char *) (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((__const unsigned char *) (__const char *) (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((__const unsigned char *) (__const char *) (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((__const unsigned char *) (__const char *) (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (
# 10 "gccbug.c"
   "--"
# 10 "gccbug.c" 3 4
   ) && ((size_t)(const void *)((
# 10 "gccbug.c"
   "--"
# 10 "gccbug.c" 3 4
   ) + 1) - (size_t)(const void *)(
# 10 "gccbug.c"
   "--"
# 10 "gccbug.c" 3 4
   ) == 1) && (__s2_len = strlen (
# 10 "gccbug.c"
   "--"
# 10 "gccbug.c" 3 4
   ), __s2_len < 4) ? (__builtin_constant_p (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ) && ((size_t)(const void *)((
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ) + 1) - (size_t)(const void *)(
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ) == 1) ? __builtin_strcmp (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   , 
# 10 "gccbug.c"
   "--"
# 10 "gccbug.c" 3 4
   ) : (__extension__ ({ __const unsigned char *__s1 = (__const unsigned char *) (__const char *) (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   ); register int __result = __s1[0] - ((__const unsigned char *) (__const char *) (
# 10 "gccbug.c"
   "--"
# 10 "gccbug.c" 3 4
   ))[0]; if (__s2_len > 0 && __result == 0) { __result = (__s1[1] - ((__const unsigned char *) (__const char *) (
# 10 "gccbug.c"
   "--"
# 10 "gccbug.c" 3 4
   ))[1]); if (__s2_len > 1 && __result == 0) { __result = (__s1[2] - ((__const unsigned char *) (__const char *) (
# 10 "gccbug.c"
   "--"
# 10 "gccbug.c" 3 4
   ))[2]); if (__s2_len > 2 && __result == 0) __result = (__s1[3] - ((__const unsigned char *) (__const char *) (
# 10 "gccbug.c"
   "--"
# 10 "gccbug.c" 3 4
   ))[3]); } } __result; }))) : __builtin_strcmp (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   , 
# 10 "gccbug.c"
   "--"
# 10 "gccbug.c" 3 4
   )))); }) : strncmp (
# 10 "gccbug.c"
   arg
# 10 "gccbug.c" 3 4
   , 
# 10 "gccbug.c"
   "--"
# 10 "gccbug.c" 3 4
   , 
# 10 "gccbug.c"
   2
# 10 "gccbug.c" 3 4
   ))) 
# 10 "gccbug.c"
   != 0
# 10 "gccbug.c" 3 4
   ) ? (void) (0) : (__assert_fail (
# 10 "gccbug.c"
   "(__extension__ (__builtin_constant_p (1) && ((__builtin_constant_p (arg) && strlen (arg) < ((size_t) (1))) || (__builtin_constant_p (\"-\") && strlen (\"-\") < ((size_t) (1)))) ? __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (arg) && __builtin_constant_p (\"-\") && (__s1_len = strlen (arg), __s2_len = strlen (\"-\"), (!((size_t)(const void *)((arg) + 1) - (size_t)(const void *)(arg) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((\"-\") + 1) - (size_t)(const void *)(\"-\") == 1) || __s2_len >= 4)) ? __builtin_strcmp (arg, \"-\") : (__builtin_constant_p (arg) && ((size_t)(const void *)((arg) + 1) - (size_t)(const void *)(arg) == 1) && (__s1_len = strlen (arg), __s1_len < 4) ? (__builtin_constant_p (\"-\") && ((size_t)(const void *)((\"-\") + 1) - (size_t)(const void *)(\"-\") == 1) ? __builtin_strcmp (arg, \"-\") : (__extension__ ({ __const unsigned char *__s2 = (__const unsigned char *) (__const char *) (\"-\"); register int __result = (((__const unsigned char *) (__const char *) (arg))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((__const unsigned char *) (__const char *) (arg))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((__const unsigned char *) (__const char *) (arg))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((__const unsigned char *) (__const char *) (arg))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (\"-\") && ((size_t)(const void *)((\"-\") + 1) - (size_t)(const void *)(\"-\") == 1) && (__s2_len = strlen (\"-\"), __s2_len < 4) ? (__builtin_constant_p (arg) && ((size_t)(const void *)((arg) + 1) - (size_t)(const void *)(arg) == 1) ? __builtin_strcmp (arg, \"-\") : (__extension__ ({ __const unsigned char *__s1 = (__const unsigned char *) (__const char *) (arg); register int __result = __s1[0] - ((__const unsigned char *) (__const char *) (\"-\"))[0]; if (__s2_len > 0 && __result == 0) { __result = (__s1[1] - ((__const unsigned char *) (__const char *) (\"-\"))[1]); if (__s2_len > 1 && __result == 0) { __result = (__s1[2] - ((__const unsigned char *) (__const char *) (\"-\"))[2]); if (__s2_len > 2 && __result == 0) __result = (__s1[3] - ((__const unsigned char *) (__const char *) (\"-\"))[3]); } } __result; }))) : __builtin_strcmp (arg, \"-\")))); }) : strncmp (arg, \"-\", 1))) == 0 && (__extension__ (__builtin_constant_p (2) && ((__builtin_constant_p (arg) && strlen (arg) < ((size_t) (2))) || (__builtin_constant_p (\"--\") && strlen (\"--\") < ((size_t) (2)))) ? __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (arg) && __builtin_constant_p (\"--\") && (__s1_len = strlen (arg), __s2_len = strlen (\"--\"), (!((size_t)(const void *)((arg) + 1) - (size_t)(const void *)(arg) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((\"--\") + 1) - (size_t)(const void *)(\"--\") == 1) || __s2_len >= 4)) ? __builtin_strcmp (arg, \"--\") : (__builtin_constant_p (arg) && ((size_t)(const void *)((arg) + 1) - (size_t)(const void *)(arg) == 1) && (__s1_len = strlen (arg), __s1_len < 4) ? (__builtin_constant_p (\"--\") && ((size_t)(const void *)((\"--\") + 1) - (size_t)(const void *)(\"--\") == 1) ? __builtin_strcmp (arg, \"--\") : (__extension__ ({ __const unsigned char *__s2 = (__const unsigned char *) (__const char *) (\"--\"); register int __result = (((__const unsigned char *) (__const char *) (arg))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((__const unsigned char *) (__const char *) (arg))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((__const unsigned char *) (__const char *) (arg))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((__const unsigned char *) (__const char *) (arg))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (\"--\") && ((size_t)(const void *)((\"--\") + 1) - (size_t)(const void *)(\"--\") == 1) && (__s2_len = strlen (\"--\"), __s2_len < 4) ? (__builtin_constant_p (arg) && ((size_t)(const void *)((arg) + 1) - (size_t)(const void *)(arg) == 1) ? __builtin_strcmp (arg, \"--\") : (__extension__ ({ __const unsigned char *__s1 = (__const unsigned char *) (__const char *) (arg); register int __result = __s1[0] - ((__const unsigned char *) (__const char *) (\"--\"))[0]; if (__s2_len > 0 && __result == 0) { __result = (__s1[1] - ((__const unsigned char *) (__const char *) (\"--\"))[1]); if (__s2_len > 1 && __result == 0) { __result = (__s1[2] - ((__const unsigned char *) (__const char *) (\"--\"))[2]); if (__s2_len > 2 && __result == 0) __result = (__s1[3] - ((__const unsigned char *) (__const char *) (\"--\"))[3]); } } __result; }))) : __builtin_strcmp (arg, \"--\")))); }) : strncmp (arg, \"--\", 2))) != 0"
# 10 "gccbug.c" 3 4
   , "gccbug.c", 10, __PRETTY_FUNCTION__), (void) (0)))
# 10 "gccbug.c"
                                                                  ;
    return (arg[1] == 'a');
}
¡Ay! ¡No sé si puedo reconocer una afirmación si la activa - ciertamente no se parece al texto del código fuente! (esta es la versión GCC 9.2.0 que se ejecuta en el antiguo rhel 5 Linux.)