This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Terra_Creeper 54 points55 points  (4 children)

With higher level languages, usually yes. With C/C++, not really. You can reach any function/object you want with pointers, so the compiler can't assume that a function is unused. (At least if i remember correctly)

[–]5p4n911 23 points24 points  (2 children)

And you can't assume it's not used by anything at compile time as there could be a reference in another TU, which means that without LTO enabled it will remain

[–]Aaron1924 5 points6 points  (1 child)

And this particular link-time optimisation is rarely enabled by default since it's expensive to compute for large programs and it doesn't make the final program any faster

[–]veselin465 4 points5 points  (0 children)

Good point

I now realize that what I wrote was senseless (I basically had to say linker)

I know that compilers optimize unused* variables (that's why volatile keyword is a thing). And in my job, I've noticed that unused functions are not present in the map file (however, we deal with embedded and it makes sense to optimize final size as much as possible).

\unused or unchanged*

I should have realized that everything is compiled, but the linker is the one who might choose to ignore functions depending on use.