Merrill said:
Merrill & Michele wrote:
I know that for my own programs, the things that precede the main call
are
either remarks or begin with a hash. What else can you put up there?
"Eric Sosman" :
Declarations and definitions of functions, types, and
variables. In short, any (correct) code:
[...]
How about:
int i = 0;
Fine: this is a variable definition, with an
initializer.
Not fine: this is an executable statement, and an
executable statement can exist only inside the body of a
function definition. It cannot "stand alone."
Not fine: a semicolon is required.
}
MPJ
(I can't imagine that that is kosher, but I'm frequently surprised.)
Examine my list of possibilities again: You can have
(1) declarations and (2) definitions of (A) functions,
(B) types, and (C) variables. That's six combinations:
1A: Function declarations
int foo(double);
void bar(long time_no_see);
1B: Type declarations
struct this { double toil; double trouble; };
union jack { char coal[128]; long john_silver; };
enum fruit { APPLE, BANANA, CRANBERRY };
1C: Variable declarations
extern struct this global_that;
extern double global_trouble;
2A: Function definitions
int foo(double x) { return x > 0.0; }
void bar(long time_no_see) {
printf ("%ld\n", time_no_see);
}
2B: Type definitions
(Well, I lied: You can't really "define" a type.
Chalk it up to a failed attempt at brevity.)
2C: Variable definitions
static double electricity;
char *situation = "hopeless";
enum fruit peelable_fruits[] = {
APPLE, BANANA };
Now, to ward off my fellow pedants let me emphasize
that there are several things wrong with this list. The
main thing is that every definition also serves as a
declaration, so the nice, neat "1 or 2" categorization
above isn't quite right. Also, the Standard talks about
something called a "tentative definition," which is really
just a formalization of how the information about a single
data object can be gathered from several bits of source.
Judging from some of the questions you've asked I suspect
that a thorough study of such subtleties would do more harm
than good at this point; return to the matter once your
grasp of the structure of C programs is firmer.