Skip to content
Yu-Jie Lin edited this page Aug 7, 2014 · 6 revisions

This page was created when I trying to learn GNU Autotools and realized that my C skill wasn't good enough.

  • extern to declare within function definition:

    I somehow coded to use getopt without including unistd.h and the optarg is needed, so I simply inserted the following inside at the beginning of main function:

    extern char *optarg;

    Although it works, I didn't entirely sure what really is until I read on Wikipedia:

    An external variable may also be declared inside a function. In this case the extern keyword must be used, otherwise the compiler will consider it a definition of a local variable, which has a different scope, lifetime and initial value. This declaration will only be visible inside the function instead of throughout the function’s module.

Clone this wiki locally