|
|
Invisible wrote:
> I know a header file can theoretically contain anything. But I always
> thought that the idea was to put only public things in a header file,
> because if it's not in the header file, other files can't know it exists
> so it can't be accessed.
No, it's so that there's only one place to change it when you change it. The
same reason you'd use an "include" in any other language or document or
whatever.
If it's not declared, you can't easily use it from outside where it's
defined. One declares it in a header file so one doesn't have to type it out
all the time or risk getting the declaration wrong.
However, sometimes when I'm debugging stuff that's just breaking deep in the
bowels of someone else's program, I'll do something like
{ extern int write(int,char*,int); write(1,"#1\n",3); }
just to put in a debugging line to tell me whether it crashed before
or after that point, which prevents me from having to #include the
right pile of header files to declare write() properly.
> Java and Pascal I already have quite extensive experience with.
> (Although I imagine since the last time I touched Java the APIs have
> been changed *again*. Oh, and I hear they kludged in generics?) Both of
> these languages know the difference between a pointer and an array,
> however.
True. C doesn't have arrays, really. At least, none with actual names.
So you have a lot of experience with Java, and you find *C's* syntax unwieldy?
--
Darren New, San Diego CA, USA (PST)
"We'd like you to back-port all the changes in 2.0
back to version 1.0."
"We've done that already. We call it 2.0."
Post a reply to this message
|
|