Why do we use different files for C ?

R

Roy

Hi ,

could you please list the reasons why we different C files for writing
code .

We use header files to logically group functionality that is related .
Is there any other reason why we need to use

different C files ?

Kindly advice,

Regards ,

Ashish
 
S

santosh

Roy said:
Hi ,

could you please list the reasons why we different C files for writing
code .

We use header files to logically group functionality that is related .
Is there any other reason why we need to use

different C files ?

Kindly advice,

Yes. For readability, maintainability and reuseability. Also for
encapsulation, though in C, it's somewhat limited.
 
C

Chris Dollin

santosh said:
Yes. For readability, maintainability and reuseability. Also for
encapsulation, though in C, it's somewhat limited.

And for multi-pair development -- different pairs can be working
on different file(group)s, and the checkins are less likely to
claintershfere.
 
K

Keith Thompson

Roy said:
could you please list the reasons why we different C files for writing
code .

We use header files to logically group functionality that is related .
Is there any other reason why we need to use

different C files ?

That wouldn't be a homework question, would it?
 
K

Kenneth Brody

Roy said:
Hi ,

could you please list the reasons why we different C files for writing
code .

We use header files to logically group functionality that is related .
Is there any other reason why we need to use

different C files ?

By "different C files", I assume you mean "multiple source files",
as opposed to having everything in a single C source file?

A single source file may be fine for small utility programs, but
when you have a large project consisting of over 750,000 lines of
code, I'm sure you can see why splitting it across more than 2,000
files makes more sense.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 
C

CBFalconer

Roy said:
could you please list the reasons why we different C files for
writing code .

We use header files to logically group functionality that is
related . Is there any other reason why we need to use different
C files ?

That is the wrong reason. We use the .h (header) files to make
certain features of the .c files available to other compilations.
That is the only purpose.
 
J

Joe Wright

Kenneth said:
By "different C files", I assume you mean "multiple source files",
as opposed to having everything in a single C source file?

A single source file may be fine for small utility programs, but
when you have a large project consisting of over 750,000 lines of
code, I'm sure you can see why splitting it across more than 2,000
files makes more sense.
What would that be, emacs? :)
 
R

Roy

What would that be, emacs? :)

Thanks guys , well was trying to see if theres more to it than what
meets the eye .

the reason that i knew was

1.using header file , to sort of encapsulate the functionality

Confusion > Splitting the source file to different files where the
functionality being split is part of the complete logical entity and
doesnt differ by much . That doesnt serve much purpose .

While it can be done if its 70000 or so lines of code simply for
readability .

Thanks all ! Cheers
 
C

cr88192

Roy said:
Hi ,

could you please list the reasons why we different C files for writing
code .

We use header files to logically group functionality that is related .
Is there any other reason why we need to use

different C files ?

limitations and editability in text editors...
saving needing to build the whole project at one.
....

most of the time, I like keeping source files to between 500 and 1000 lines.

too much smaller, and one is going berserk with the text editor (and the
annoyingly small amount of windows resources, ESP in vista, where it is
amazingly small and maybe about 20-something notepads and a few IE windows
and stuff starts breaking... FFS at least in XP I could get up to around
50-70 notepads...).

this is one thing that nearly drives me insane about Java (among other
things). uber-chibi isn't always kawaii...


now, too much than about 1000 (or maybe 2000), and typically one encounters
a kind of scrolling nightmare...
one can end up having to scroll damn near forever to find the exact function
they are looking for ("well, I know it was around here somewhere...").

except, in some rare cases...
in my compiler, my cast-conversion function (gradually ended up along in its
own file), is something like several kloc, for a single function (considered
before splitting it up, oh well...).


so, it is a tradeoff really...

by the time projects reach well into the double-digit kloc range, the need
for multiple files is obvious.

well into the tripple-digit kloc range, and a single massive source file
would seem almost insane...

"watch as I scroll around, at uber speeds, through this 450,000 line beast,
in search of a single 50-line function for which I have forgotten the
name...".

of course, anyone who doubts me is more than free to try...
 
S

santosh

by the time projects reach well into the double-digit kloc range, the need
for multiple files is obvious.

well into the tripple-digit kloc range, and a single massive source file
would seem almost insane...

"watch as I scroll around, at uber speeds, through this 450,000 line
beast, in search of a single 50-line function for which I have forgotten
the name...".

of course, anyone who doubts me is more than free to try...

You should tell this to Betov of alt.lang.asm :)
 
K

Kenneth Brody

Joe said:
Kenneth Brody wrote: [...]
A single source file may be fine for small utility programs, but
when you have a large project consisting of over 750,000 lines of
code, I'm sure you can see why splitting it across more than 2,000
files makes more sense.
What would that be, emacs? :)

I haven't used emacs since I tried it many (many!) years ago. (I
won't mention which editor I use, to avoid the whole emacs-vs-vi
discussion/war/mess.)

You could probably figure out what program I am referring to with
a few simply searches.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 
J

Joe Wright

Kenneth said:
Joe said:
Kenneth Brody wrote: [...]
A single source file may be fine for small utility programs, but
when you have a large project consisting of over 750,000 lines of
code, I'm sure you can see why splitting it across more than 2,000
files makes more sense.
What would that be, emacs? :)

I haven't used emacs since I tried it many (many!) years ago. (I
won't mention which editor I use, to avoid the whole emacs-vs-vi
discussion/war/mess.)

You could probably figure out what program I am referring to with
a few simply searches.
I won't bother. I was trying to imagine a program comprised of 2,000 .c
files and however many .h files. It's simply a larger project than I've
encountered. I mentioned emacs only because of its reputation as large
and bloated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top