secretos que primero para huevo gallina fue aplicaciones amantes c++ inline

que - c++17



¿Cómo puedo saber si una función ha sido en línea o no? (3)

Si marco alguna función como en línea, ¿hay alguna manera de saber si la función está en línea o no?


1, mira la salida del ensamblador
2, ¿por qué te importa?


Con GCC puedes usar la opción del compilador en línea:

-Winline Warn if a function can not be inlined and it was declared as inline.

El archivo man para gcc continúa diciendo:

Even with this option, the compiler will not warn about failures to inline functions declared in system headers. The compiler uses a variety of heuristics to determine whether or not to inline a function. For example, the compiler takes into account the size of the function being inlined and the amount of inlining that has already been done in the current function. Therefore, seemingly insignificant changes in the source program can cause the warnings produced by -Winline to appear or disappear.


Mira el lenguaje ensamblador que emite tu compilador. Por ejemplo, compilando con g ++:

g++ -S -c foo.c

creará un archivo llamado foo.s que contiene la salida del lenguaje ensamblador. Alternativamente, y una vez más con el conjunto de herramientas GCC, use objdump:

g++ -c foo.c objdump -d foo.o

Otros conjuntos de herramientas tienen una funcionalidad similar.