gcc provides additional builtin functions "for optimization".
One of them is void __builtin_trap (void)
which essentially is here to abort the program by executing an illegal command.
From the doc:
__builtin_trap function causes the program to exit abnormally. GCC implements this function by using a target-dependent mechanism (such as intentionally executing an illegal instruction) or by calling abort. The mechanism used may vary from release to release so you should not rely on any particular implementation.
Why would you ever use this rather than exit(1)
or abort
? Why did the gcc developers see this as an optimization function?