Take a look at this code:
#include <stdio.h> typedef int (*callback) (void *arg); callback world = NULL; int f(void *_) { printf("World!"); return 0; } int main() { printf("Hello, "); // world = f; world = &f; // both works if (world != NULL) { world(NULL); } }
When setting the world variable, both world = f; and world = &f; works.
What should i use? Does it depend on the compiler or version of C?
% gcc -v Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 8.0.0 (clang-800.0.38) Target: x86_64-apple-darwin15.6.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
source share