Find the answer to your Linux question:
Results 1 to 5 of 5
Hello, In the last few days I've learnt how to edit ,compile and build some simple programs using C/C++ languages. But there are some issues that still confuse me: 1- ...
  1. #1
    Just Joined!
    Join Date
    Jun 2009
    Posts
    16

    Beginner programming questions.....

    Hello,
    In the last few days I've learnt how to edit ,compile and build some simple programs using C/C++ languages.

    But there are some issues that still confuse me:

    1- Why is the source of a large program divided into several pieces of (.c)and (.h) files? and how do I divide a program with functions and classes and library headers into .c and .h files?
    .c --> C code
    .h --> header file (like function defenitions and #using<library.h> and DEFINE ????)

    2-Some programs have some script fiiles and perl files beside the .c/.cpp files........Why do they mix several program languages? I've heared that script files sometimes can fix problems with installing the software ...is that the only purpose? and what's the purpose of the .pl perl files???


    An example of such a program with several .c , .h , .sh , .pl files ---> is snort .......

    3- My third question is about the configure file....How does it work?How does it create the makefile??

    The reason why I'm asking is that I need to fully understand the programming of snort in order to modify it to be more suitable to my NETWORK....... Which is my graduation project....

    Thanks in advance....

  2. #2
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    You might get more responses if you didn't post a shopping list of questions....One post, one or two questions...G4143
    Make mine Arch Linux

  3. #3
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    Quote Originally Posted by ahmad2080 View Post
    Hello,
    1- Why is the source of a large program divided into several pieces of (.c)and (.h) files?
    For the sake of clarity, efficency and to avoid redundancy.
    a) Several small files are easier maintained than one single big one.
    b) "Translation units" can be compiled separately and linked together later.
    So if you change one line in one file, not the complete project has to be compiled anew. This saves time.
    c) Header files can be shared between several .c files. So the information in them needs only to be written once, and every other file knows about this.
    If this doesn't make too much sense for you, search in your learning book for "declaration versus definition".


    Quote Originally Posted by ahmad2080 View Post
    2-Some programs have some script fiiles and perl files beside the .c/.cpp files........Why do they mix several program languages? I've heared that script files sometimes can fix problems with installing the software ...is that the only purpose? and what's the purpose of the .pl perl files???
    Every programming language has its strengths and weaknesses. Choosing the right tool for a given a job is half the success. Script files are mostly convenience programs that spare you to write many commands repeatedly.


    Quote Originally Posted by ahmad2080 View Post
    3- My third question is about the configure file....How does it work?How does it create the makefile??
    It scans your computer for where all the programs it needs reside and if all necessary dependencies (other programs) are installed. These tasks need only to be done once for a given system (and project) because this information does usually not change when you modify the program.
    Debian GNU/Linux -- You know you want it.

  4. #4
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    Quote Originally Posted by ahmad2080 View Post
    But there are some issues that still confuse me:

    1- Why is the source of a large program divided into several pieces of (.c)and (.h) files? and how do I divide a program with functions and classes and library headers into .c and .h files?
    .c --> C code
    .h --> header file (like function defenitions and #using<library.h> and DEFINE ????)
    For size and organizational purposes. Sure, it may seem like overkill for a small program that's less than 100 lines to split it up between headers and source files, but when you get into multi-file programs that are several thousand (or hundreds of thousands) of lines long it gets to be a logistical nightmare to remember where and how you defined this structure or procedure.

    2-Some programs have some script fiiles and perl files beside the .c/.cpp files........Why do they mix several program languages? I've heared that script files sometimes can fix problems with installing the software ...is that the only purpose? and what's the purpose of the .pl perl files???
    In the case of Linux programs, a lot of the time the main program is written in C, but the install script is easier to do with a scripting language like Perl or Python.
    Registered Linux user #270181
    TechieMoe's Tech Rants

  5. #5
    Just Joined!
    Join Date
    Jun 2009
    Posts
    16
    @gerard:
    Actually Ive got some pretty excellent responses from GNU-Fan and techieMoe so far......
    Forgive me if I'm asking some beginner questions, but I think that posting a shopping list of questions is better than a shopping list of topics (as long as all questions are related)......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...