-
Notifications
You must be signed in to change notification settings - Fork 1
C Learning Notes
Yu-Jie Lin edited this page Jul 13, 2014
·
6 revisions
This page was created when I trying to learn GNU Autotools and realized that my C skill wasn't good enough.
Contents
-
extern
to declare within function definition:I somehow coded to use
getopt
without includingunistd.h
and theoptarg
is needed, so I simply inserted the following inside at the beginning ofmain
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.